This repository simplifies building MySQL or MariaDB Docker images with data.
Adjust your Docker Compose database service by adding a build section and changing
the image.
Before:
services:
mysql:
image: mysql:8.1.0
environment:
MYSQL_DATABASE: database_name
MYSQL_USER: user_name
MYSQL_PASSWORD: user_password
MYSQL_ROOT_PASSWORD: root_password
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 10After:
services:
mysql:
build:
context: https://github.com/pagemachine/docker-mysql-data.git#x.y.z
dockerfile: mysql.Dockerfile
additional_contexts:
data: ./data
args:
MYSQL_IMAGE_VERSION: 8.1.0
MYSQL_DATABASE: database_name
MYSQL_USER: user_name
MYSQL_PASSWORD: user_password
MYSQL_ROOT_PASSWORD: root_password
healthcheck:
test: ["CMD", "mysqladmin" ,"ping", "-h", "localhost"]
interval: 10s
timeout: 5s
retries: 10
image: registry.example/my-project/mysql:latestbuild.contextpoints to the URL of this GitHub repository, the fragment refers to a release,x.y.zin this case, try to always use the latest release.build.dockerfileis themysql.Dockerfilebuild.additional_contexts.datamust be defined and point to a local directory with*.sql,.sql.gzor.shfiles to use for populating the database on build.build.args.MYSQL_IMAGE_VERSIONmust be a valid tag of themysqlDocker image.build.args.MYSQL_DATABASEis the name of the database to create.build.args.MYSQL_USERis the username to set up for the database.build.args.MYSQL_PASSWORDis the password to set for the database user.build.args.MYSQL_ROOT_PASSWORDis the password of therootuser.imageshould set a persistent image name/tag and a registry to push this image to, this way other users will automatically pull the prebuilt image instead of building it again.
Before:
services:
mariadb:
image: mariadb:10.5.27
environment:
MARIADB_DATABASE: database_name
MARIADB_USER: user_name
MARIADB_PASSWORD: user_password
MARIADB_ROOT_PASSWORD: root_password
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 10After:
services:
mariadb:
build:
context: https://github.com/pagemachine/docker-mysql-data.git#x.y.z
dockerfile: mariadb.Dockerfile
additional_contexts:
data: ./data
args:
MARIADB_IMAGE_VERSION: 10.5.27
MARIADB_DATABASE: database_name
MARIADB_USER: user_name
MARIADB_PASSWORD: user_password
MARIADB_ROOT_PASSWORD: root_password
healthcheck:
test: ["CMD", "healthcheck.sh", "--connect", "--innodb_initialized"]
interval: 10s
timeout: 5s
retries: 10
image: registry.example/my-project/mariadb:latestbuild.contextpoints to the URL of this GitHub repository, the fragment refers to a release,x.y.zin this case, try to always use the latest release.build.dockerfileis themariadb.Dockerfilebuild.additional_contexts.datamust be defined and point to a local directory with*.sql,.sql.gzor.shfiles to use for populating the database on build.build.args.MARIADB_IMAGE_VERSIONmust be a valid tag of themariadbDocker image.build.args.MARIADB_DATABASEis the name of the database to create.build.args.MARIADB_USERis the username to set up for the database.build.args.MARIADB_PASSWORDis the password to set for the database user.build.args.MARIADB_ROOT_PASSWORDis the password of therootuser.imageshould set a persistent image name/tag and a registry to push this image to, this way other users will automatically pull the prebuilt image instead of building it again.