docker-compose-environment-variables-for-mysql¶
docker-compose-environment-variables-for-mysql refers to the configuration of runtime parameters within a docker-compose.yml file to set up a [[MySQL]] container.^[600-developer__docker__docker-compose__docker-compouse-02.md]
Configuration¶
In Docker Compose, these variables are defined under the environment section of the service definition^[600-developer__docker__docker-compose__docker-compouse-02.md].
Common variables include creating a specific user, setting passwords, and defining the initial database^[600-developer__docker__docker-compose__docker-compouse-02.md].
Example Configuration¶
The following docker-compose.yml example demonstrates how to instantiate a MySQL 5.7 database with custom credentials and database name^[600-developer__docker__docker-compose__docker-compouse-02.md]:
version: "3"
services:
db:
image: mysql:5.7
ports:
- "33060:3306"
volumes:
- ./data:/var/lib/mysql
restart: always
environment:
- MYSQL_USER=tommy
- MYSQL_PASSWORD=tommy
- MYSQL_DATABASE=dockerDb
- MYSQL_ROOT_PASSWORD=root
Common Variables¶
MYSQL_USER: Creates a new user with superuser privileges^[600-developer__docker__docker-compose__docker-compouse-02.md].MYSQL_PASSWORD: Sets the password for the new user created byMYSQL_USER^[600-developer__docker__docker-compose__docker-compouse-02.md].MYSQL_DATABASE: Creates a database with this name on startup^[600-developer__docker__docker-compose__docker-compouse-02.md].MYSQL_ROOT_PASSWORD: Sets the password for therootsuperuser; this variable is required^[600-developer__docker__docker-compose__docker-compouse-02.md].
Related Concepts¶
- [[docker-compouse-02]]
- [[MySQL]]
- Docker Compose
Sources¶
^[600-developer__docker__docker-compose__docker-compouse-02.md]