From fe1028a2059a7ffdfb8b63877ab98a3329e1ac2c Mon Sep 17 00:00:00 2001 From: Manuel Date: Thu, 8 Nov 2018 14:46:39 +0100 Subject: [PATCH 1/3] Using dockerize as entry point --- Dockerfile | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 678e58e..a631b70 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,13 +3,18 @@ LABEL maintainer "Fco. Javier Delgado del Hoyo " COPY ["run.sh", "backup.sh", "restore.sh", "/"] -RUN apk add --update bash mysql-client gzip && rm -rf /var/cache/apk/* && mkdir /backup &&\ +RUN apk add --update bash mysql-client gzip openssl && rm -rf /var/cache/apk/* && mkdir /backup &&\ chmod u+x /backup.sh /restore.sh +ENV DOCKERIZE_VERSION v0.6.1 +RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSION/dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ + && tar -C /usr/local/bin -xzvf dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz \ + && rm dockerize-alpine-linux-amd64-$DOCKERIZE_VERSION.tar.gz + ENV CRON_TIME="0 3 * * sun" \ MYSQL_HOST="mysql" \ MYSQL_PORT="3306" VOLUME ["/backup"] -CMD ["/run.sh"] +CMD dockerize -wait tcp://${MYSQL_HOST}:3306 /run.sh From d5eca7afc538a0eb522d6ab09c450a9f523b3e47 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 9 Nov 2018 15:55:53 +0100 Subject: [PATCH 2/3] Global MySQL port and timeout variable --- Dockerfile | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index a631b70..2e141e2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -13,8 +13,9 @@ RUN wget https://github.com/jwilder/dockerize/releases/download/$DOCKERIZE_VERSI ENV CRON_TIME="0 3 * * sun" \ MYSQL_HOST="mysql" \ - MYSQL_PORT="3306" + MYSQL_PORT="3306" \ + TIMEOUT="10s" VOLUME ["/backup"] -CMD dockerize -wait tcp://${MYSQL_HOST}:3306 /run.sh +CMD dockerize -wait tcp://${MYSQL_HOST}:${MYSQL_PORT} -timeout ${TIMEOUT} /run.sh From a4ed62c9ccf37a13f1c566b711a37a7a0c511383 Mon Sep 17 00:00:00 2001 From: Manuel Date: Fri, 9 Nov 2018 16:09:18 +0100 Subject: [PATCH 3/3] Timeout documentation --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index f95276f..1903bae 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ docker container run -d \ - `MAX_BACKUPS`: The number of backups to keep. When reaching the limit, the old backup will be discarded. No limit by default. - `INIT_BACKUP`: If set, create a backup when the container starts. - `INIT_RESTORE_LATEST`: Ff set, restores latest backup. +- `TIMEOUT`: Wait a given number of seconds for the database to be ready and make the first backup, `10s` by default. After that time, the initial attempt for backup gives up and only the Cron job will try to make a backup. If you want to make this image the perfect companion of your MySQL container, use [docker-compose](https://docs.docker.com/compose/). You can add more services that will be able to connect to the MySQL image using the name `my_mariadb`, note that you only expose the port `3306` internally to the servers and not to the host: