Setup MySQL with Docker Compose
A setup guideline for MySQL and Docker Compose
Photo by Rubaitul Azad on Unsplash
Setup MySQL with Docker Compose
A setup guideline for MySQL and Docker Compose
If you are not a member, you can read the article here.
In this article we are going to setup a MySQL instance with Docker Compose. This article is part of a series of tutorials related to Docker Compose. Check out more here.
[embed]Tutorials collection (updated continuously) DevOps, Metrics, Java and moremedium.com
Setup MySQL
MySQL is an open-source relational database management system (RDBMS). This tutorial will show you how to setup the MySQL in Docker Compose. We will use the official docker image from Docker Hub.
We will also expose the port 3306 to be able to connect to it from the local machine. Also it is recommended to add a network to the service in order to connect to it from other Docker containers.
networks:
tutorials:
external: true
The following template can be used to start a MySQL instance:
services:
mysql:
image: mysql:latest
restart: always
environment:
MYSQL_DATABASE: 'DB_NAME'
MYSQL_USER: 'DB_USER'
MYSQL_PASSWORD: 'DB_PASSWORD'
MYSQL_ROOT_PASSWORD: 'DB_ROOT_PASSWORD'
ports:
- '3306:3306'
volumes:
- DB_NAME-db:/var/lib/mysql
networks:
- tutorials
volumes:
DB_NAME-db:
networks:
tutorials:
external: true
Feel free to change the template names based on your needs:
DB_NAME - the user name
DB_PASSWORD - the user password
DB_ROOT_PASSWORD - the admin password
Start MySQL instance:
$ docker compose up -d
Stop MySQL instance:
$ docker compose down
You can connect to the service:
- from host machine using host
localhostand port3306 - from other docker containers using host
mysqland port3306
Useful links
Other pieces from the tutorials series
[embed]Setup nginx as Reverse Proxy with Docker Compose medium.com
If you think that my guide was useful, you can support my work here.
메타데이터
- post_id
- 82fe1951ecab
- slug
- setup-mysql-in-docker-compose-82fe1951ecab
- url
- https://medium.com/@szilardmatis/setup-mysql-in-docker-compose-82fe1951ecab
- canonical_url
- https://medium.com/@szilardmatis/setup-mysql-in-docker-compose-82fe1951ecab
- author_url
- https://medium.com/@szilardmatis
- status
- ok
- fetched_at
- 2026-07-20 19:09:02