Docker
Run MySQL Server Using Docker On A Remote Machine
Learn how to run a MySQL server using Docker on a remote machine, connect with MySQL Workbench, and manage the container safely.

Running a MySQL server on a remote machine using Docker can simplify database setup for learning, testing, and practice environments. In this guide, we will set up a remote MySQL server with Docker and connect to it from MySQL Workbench.
This is useful for QA engineers who want to practice database testing, API testing, and integration workflows against a real database server.
Step 1: Get A Server You Can Access Remotely
In the original tutorial, I used DigitalOcean. You can use a VPS from any provider you prefer.
Create the server with these basic specifications:
- Operating system: Ubuntu.
- Authentication: password or SSH key.
- Plan: the cheapest small plan is enough for practice.




Step 2: SSH Into The Droplet Or Use The Browser Console
Once the droplet is created, you can SSH into it from your terminal, CMD, or PowerShell.
ssh root@your_droplet_ip
Alternatively, you can use the console provided in the DigitalOcean browser interface.


Step 3: Install Docker
Run the following commands on the server to install Docker:
apt-get update
apt-get install -y docker.io
Verify Docker is installed:
docker --version
Step 4: Run The MySQL Container
Use this command to run the MySQL container:
docker run --name mysql-demo \
-e MYSQL_ROOT_PASSWORD=SuperSecretForRoot \
--restart always \
-p 3307:3306 \
-d mysql:8.0
Command breakdown:
| Option | Meaning |
|---|---|
--name mysql-demo | Names the container mysql-demo. |
-e MYSQL_ROOT_PASSWORD=SuperSecretForRoot | Sets the root password for MySQL. Replace this with your own password. |
--restart always | Restarts the container automatically if it stops. |
-p 3307:3306 | Maps port 3307 on the server to port 3306 inside the container. |
-d mysql:8.0 | Runs MySQL 8.0 in detached mode. |

Verify that the container is running and that port 3307 is available:
docker ps

Step 5: Open MySQL Workbench
If you do not have MySQL Workbench installed, download it from the official MySQL Workbench page:
https://dev.mysql.com/downloads/workbench/
Step 6: Create A Connection In MySQL Workbench
In MySQL Workbench:
- Open MySQL Workbench.
- Click + Add New Connection.
- Enter the connection details.
- Click Test Connection.
- Click OK to save the connection.
Use these values:
| Field | Value |
|---|---|
| Connection Name | MySQL Docker |
| Hostname | Your droplet IP address |
| Port | 3307 |
| Username | root |
| Password | The password you used in MYSQL_ROOT_PASSWORD |


Restart The Container If MySQL Is Stuck
If you cannot access the MySQL server or the container is stuck, restart the container. These commands assume the container name is mysql-demo.
Stop the container:
docker stop mysql-demo
Start the container:
docker start mysql-demo
Restart the container:
docker restart mysql-demo
Optional: Use A Subdomain Instead Of An IP Address
If you want to connect using a subdomain like mysql.mydomain.com instead of an IP address, create an A record that points to your server.
General steps:
- Log in to your domain registrar or DNS provider.
- Open DNS management.
- Add an A record.
- Set the host to your subdomain, such as
mysql. - Point it to your droplet IP address.
- Save the record and wait for DNS propagation.
Important Security Note
For practice, exposing MySQL on a public server can be acceptable if you understand the risk, use a strong password, and restrict access. For anything serious, avoid exposing a database port publicly.
Safer options include:
- Restrict port
3307to your own IP address using a firewall. - Use SSH tunneling instead of opening MySQL to the internet.
- Keep this setup for disposable practice environments only.
Example SSH tunnel:
ssh -L 3307:127.0.0.1:3307 root@your_droplet_ip
Then connect MySQL Workbench to 127.0.0.1 on port 3307.
The original Kajabi page included an Nginx reverse proxy example, but HTTP reverse proxying is not the normal way to expose MySQL. For a database, firewall rules or SSH tunneling are a better fit.
