Skip to content

Commit 8f7fc32

Browse files
committed
Add HEALTHCHECK directive
This commit adds HEALTHCHECK instructions to the Dockerfiles. The actual healthcheck logic is in the `healthcheck.sh` file, which is copied into the image via a `COPY` instruction in the Dockerfiles. The reason for the separate script vs. inline in the Dockerfile is that AFAIK, environment replacement isn't supported by the `HEALTCHECK` instruction.
1 parent b2b4fcf commit 8f7fc32

File tree

8 files changed

+32
-0
lines changed

8 files changed

+32
-0
lines changed

5.5/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,12 @@ RUN mkdir -p /var/lib/mysql /var/run/mysqld \
7171
VOLUME /var/lib/mysql
7272

7373
COPY docker-entrypoint.sh /usr/local/bin/
74+
COPY healthcheck.sh /usr/local/bin/
75+
7476
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
77+
78+
HEALTHCHECK CMD ["/bin/bash", "/usr/local/bin/healthcheck.sh"]
79+
7580
ENTRYPOINT ["docker-entrypoint.sh"]
7681

7782
EXPOSE 3306

5.5/healthcheck.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#/bin/bash
2+
3+
mysql --protocol=socket -hlocalhost -uroot -p$MYSQL_ROOT_PASSWORD -e 'SELECT 1'

5.6/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ RUN sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/my.cnf \
5757
VOLUME /var/lib/mysql
5858

5959
COPY docker-entrypoint.sh /usr/local/bin/
60+
COPY healthcheck.sh /usr/local/bin/
61+
6062
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
63+
64+
HEALTHCHECK CMD ["/bin/bash", "/usr/local/bin/healthcheck.sh"]
65+
6166
ENTRYPOINT ["docker-entrypoint.sh"]
6267

6368
EXPOSE 3306

5.6/healthcheck.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#/bin/bash
2+
3+
mysql --protocol=socket -hlocalhost -uroot -p$MYSQL_ROOT_PASSWORD -e 'SELECT 1'

5.7/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ RUN sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/mysql.conf.d/mysqld.cnf \
5757
VOLUME /var/lib/mysql
5858

5959
COPY docker-entrypoint.sh /usr/local/bin/
60+
COPY healthcheck.sh /usr/local/bin/
61+
6062
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
63+
64+
HEALTHCHECK CMD ["/bin/bash", "/usr/local/bin/healthcheck.sh"]
65+
6166
ENTRYPOINT ["docker-entrypoint.sh"]
6267

6368
EXPOSE 3306

5.7/healthcheck.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#/bin/bash
2+
3+
mysql --protocol=socket -hlocalhost -uroot -p$MYSQL_ROOT_PASSWORD -e 'SELECT 1'

8.0/Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,12 @@ RUN sed -Ei 's/^(bind-address|log)/#&/' /etc/mysql/mysql.conf.d/mysqld.cnf \
5757
VOLUME /var/lib/mysql
5858

5959
COPY docker-entrypoint.sh /usr/local/bin/
60+
COPY healthcheck.sh /usr/local/bin/
61+
6062
RUN ln -s usr/local/bin/docker-entrypoint.sh /entrypoint.sh # backwards compat
63+
64+
HEALTHCHECK CMD ["/bin/bash", "/usr/local/bin/healthcheck.sh"]
65+
6166
ENTRYPOINT ["docker-entrypoint.sh"]
6267

6368
EXPOSE 3306

8.0/healthcheck.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
#/bin/bash
2+
3+
mysql --protocol=socket -hlocalhost -uroot -p$MYSQL_ROOT_PASSWORD -e 'SELECT 1'

0 commit comments

Comments
 (0)