1001Ferramentas
🐬Dev

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?
Add MYSQL_DATABASE, MYSQL_USER and MYSQL_PASSWORD to the environment block. The page does not generate those lines, and they only take effect on the first startup with an empty volume.
I changed the password and the container ignored it. Why?
The MySQL entrypoint applies the variables only when the data directory is empty. With an existing volume it just starts the server with the old password. Run docker compose down -v to start over.
How does my app connect to it?
From another container on the same compose network, use mysql as the host and port 3306. From your own machine, use 127.0.0.1 on the published port.

Related Tools