DbSchema Database Designer

DbSchema | How to Run MySql in a Docker Container

Publish on DbSchema Blog >>>

In this article, we are going to see a step-by-step tutorial on how to run a MySQL database in a Docker Container.

1.Downloading a MySQL Server Docker Image

To download the image, open the command line and type this command:

docker pull mysql/mysql-server:latest

The :latest tag will download the latest version of MySQL. If you want do download a specific version, simply replace the
latest (Ex: mysql-server :8.0)

2.Start a MySQL Container in Docker

The next step is to run a container in Docker with the MySQL image. To do this, execute the next command:

docker run --name=mysql1 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -d mysql/mysql-server:8.0

Let’s break down this command to understand it better:

  • run - will run a new command in a new Docker container
  • –name - will give a name to the new container created
  • -p - will make the internal docker port visible outside docker
    ***-e** - will change the root password. Here you can insert whatever password you want
  • mysql/mysql-server:8.0 - will specify what image to run in the newly created container

To verify if the container was created and running, we can execute a docker ps (process status) command:

docker ps

CONTAINER ID        IMAGE                      COMMAND                  CREATED         STATUS                            PORTS                  NAMES
79742fe73ea9        mysql/mysql-server:8.0     "/entrypoint.sh mysq…"   24 hours ago    Up 6 seconds (health: starting)   3306/tcp, 33060/tcp    mysql1

This will list all the running containers as shown above.

In the status column of the result from above, you can see the (health: starting) mention. After the container is initialized
and ready to run, you will se it change to (healthy).

3.Connecting to MySQL Server from within the container

To connect, we will first run the next command:

docker exec -it mysql1 mysql -uroot -p

This will require the root password set in the previous step. After inserting the password, you should be inside MySQL


Type exit to leave the program.

4.Stopping the MySQL container

To stop the container, simply execute the next command:

docker stop mysql1

5.Deleting the MySQL container

To delete the container, make sure that it is stopped. Then, execute this command:

docker rm mysql1

Visually Manage Databases using DbSchema

DbSchema is a databases client and visual designer. DbSchema has a free Community Edition, which can be downloaded here.
DbSchema main features include:

DbSchema Designer alt >

Interactive Diagrams

Design tables, column and foreign keys directly in diagrams, by double-clicking them. Changes will be saved to the design model and, if DbSchema is connected to the database also into the database. More.

Connection Dialog alt >

Simple Connection Dialog

Choose the database location, the user and password, and simply get connected. Choose 'Edit Manually' into the JDBC URL combo to enter a custom URL. More.

Relational Data Explorer alt >

Relational Data Explorer

Explore data from multiple tables simultaneously, using foreign keys or virtual foreign keys. Double-click cells to edit the data. More.

Query Builder alt >

Query Builder

Create SQL Queries featuring JOINS, GROUP BY, ORDER BY just using the mouse. More.

SQL Query Editor alt >

SQL Query Editor

Edit and execute SQL Queries. The editor is autocompletion-enabled. More.

Schema Synchronization alt >

Design Schema in Team & Schema Deployment

DbSchema is using the design model, a copy of the schema structure, independent of the database.
The design model can be saved to file and shared in a team.
Connecting to another database you may compare the design model with the database, commit the differences or merge them in the design model. More.

Dark Theme alt >

Dark Theme

Configurable styles & dark theme. More.

Many features are available in the free Community edition.
The Pro edition adds capabilities to save the design to the model file, design schema in team and deploy the schema on multiple databases.

DbSchema can be downloaded for free. No registration is required.