docker-compose MySQL Generator
Generates a ready-to-use docker-compose for MySQL, with the root password, port 3306 published and a persistent volume. Pick the image tag and start the database.
YAML
β
A local MySQL that survives a restart
You need a MySQL instance for development and you would rather not install the server on the host, with a service starting at boot and the wrong version clashing with another project. A container solves that, and then the next questions arrive: what does the docker-compose.yml look like, which environment variable sets the password, and where does the data live once you tear everything down.
The generated file defines one service named mysql with the image tag you pick, MYSQL_ROOT_PASSWORD, port 3306 published and a named volume called mydata mounted at /var/lib/mysql. That volume is the part that matters: without it, a docker compose down takes the database with it. There are only two fields here, version and root password. Despite what the description suggests, no MYSQL_DATABASE or MYSQL_USER is generated.
If 3306 is already taken on your machine, change the left side of the mapping to 3307 and connect on that port. Remember that the MySQL variables only apply on the very first startup, while the volume is still empty; changing the password later means wiping it with docker compose down -v. And do not commit the file with a real password, local environment or not. The YAML is assembled in the browser.
Frequently asked questions
How do I create a database and user at startup?
I changed the password and the container ignored it. Why?
How does my app connect to it?
Related Tools
Docker Run β Compose
Convert a docker run command to the equivalent docker-compose.yml automatically. Maps ports, volumes, environment variables, networks and restart policies.
docker-compose Redis Generator
Generates a ready-to-use docker-compose for Redis, publishing port 6379 with a persistent volume. Pick the image tag and spin up your local cache or broker with one command.
docker-compose PostgreSQL Generator
Generate a ready-to-use docker-compose for PostgreSQL, with user, password, database and a persistent volume set up. Spin up your local DB with one command.