Created
December 12, 2018 20:42
-
-
Save bcremer/9ea822259214fa1161e15bc2203a20d9 to your computer and use it in GitHub Desktop.
Multi-Stage Dockerfile to prepopulated MySQL Image
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
## See: https://serverfault.com/a/915845/17736 | |
FROM percona/percona-server:5.7 as builder | |
USER root | |
RUN mkdir -p /initialized-db && chown -R mysql:mysql /initialized-db | |
# 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 $@\"/", "/docker-entrypoint.sh"] | |
# needed for intialization | |
ENV MYSQL_ROOT_PASSWORD=apidev | |
USER mysql | |
COPY *.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 ["/docker-entrypoint.sh", "mysqld", "--datadir", "/initialized-db"] | |
FROM percona/percona-server:5.7 | |
COPY --from=builder /initialized-db /initialized-db | |
USER root | |
RUN chown -R mysql:mysql /initialized-db | |
USER mysql | |
CMD ["--datadir", "/initialized-db"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Disregard, Line 16 actually takes the .sql and places it in /docker-entrypoint-initdb.d/ which is actually used to initalize the DB when the
/docker-entrypoint.sh
script is executed.Thanks for this example, it helped me in my implementation.