Docker, MySQL

docker-compose.yml for MySQL For Local Development

This post provides another basic docker-compose.yml .This time is to create a MySQL container with initial user accounts.

Tested with:

  1. Docker for Windows. Please install this before proceeding.
  2. MySQL 8. This is the version of MySQL that our Docker image has.
  3. Windows 10 64-bit

docker-compose.yml: A YAML File

When we use this to create a Docker container, the MySQL instance will have an initial user with turreta username. Moreover, it will enable the root user and create a database.

How to Use the docker-compose.yml For MySQL

Next, open a Windows Command Line prompt and cd to the directory where the docker-compose.yml file is. Then, run the following commands.

1. Pull the image from Docker Hub to the local machine.

To pull the image from Docker Hub, run the following command on the command-line window. If we look at our docker-compose.yml again, we see mysql:8. This means docker-compose will put an image of mysql:8 from Docker Hub.

2. Create and Run a MariaDB container

After pulling the image, we can now create a Docker container for our image. Although it took two steps to start up a container, we don’t have to do it all the time. We can use the following command to pull an image from Dock Hub and start a Docker container in one command.

Once we successfully started the MySQL Docker container, we can already connect our applications to the database.

This post is part of the Docker For Developers tutorial.


Got comments or suggestions? We disabled the comments on this site to fight off spammers, but you can still contact us via our Facebook page!.

You Might Also Like

One comment

  1. 1

Comments are closed.