Last active
April 23, 2020 13:45
-
-
Save elowy01/81874099731fd7fa39d1992eca345fec to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example extracted from : | |
https://github.com/iamdvr/prepopulated-mysql-container-example | |
### The DockerFile is : | |
FROM mariadb:latest as builder | |
# That file does the DB initialization but also runs mysql daemon, by removing the last line it will only init | |
RUN ["sed", "-i", "s/exec \"$@\"/echo \"not running $@\"/", "/usr/local/bin/docker-entrypoint.sh"] | |
# needed for intialization | |
ENV MYSQL_ROOT_PASSWORD=root | |
COPY ./setup.sql /docker-entrypoint-initdb.d/ | |
# Need to change the datadir to something else that /var/lib/mysql because the parent docker file defines it as a volume. | |
# https://docs.docker.com/engine/reference/builder/#volume : | |
# Changing the volume from within the Dockerfile: If any build steps change the data within the volume after | |
# it has been declared, those changes will be discarded. | |
RUN ["/usr/local/bin/docker-entrypoint.sh", "mysqld", "--datadir", "/initialized-db", "--aria-log-dir-path", "/initialized-db"] | |
FROM mariadb:latest | |
COPY --from=builder /initialized-db /var/lib/mysql | |
### You need to run it in this particular way or the COPY command | |
# will not work: | |
$ docker build -t mysql_and_docker . -f Dockerile | |
# Then you run a container and expose port 3306 | |
$ docker run --name=mysql2 -e MYSQL_ROOT_HOST=% -p 3306:3306 -d mysql_and_docker | |
# Then you can connect to mysql server and see the prepopulated schema: | |
$ docker exec -it mysql2 mysql -u root -p # password is 'root' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment