When replacing a container currently we:
1. Boot the new container
2. Wait for it to become healthy
3. Stop the old container
Traefik will send requests to the old container until it notices that it
is unhealthy. But it may have stopped serving requests before that point
which can result in errors.
To get round that the new boot process is:
1. Create a directory with a single file on the host
2. Boot the new container, mounting the cord file into /tmp and
including a check for the file in the docker healthcheck
3. Wait for it to become healthy
4. Delete the healthcheck file ("cut the cord") for the old container
5. Wait for it to become unhealthy and give Traefik a couple of seconds
to notice
6. Stop the old container
The extra steps ensure that Traefik stops sending requests before the
old container is shutdown.
33 lines
1.2 KiB
Docker
33 lines
1.2 KiB
Docker
FROM ruby:3.2
|
|
|
|
WORKDIR /app
|
|
|
|
ENV VERBOSE=true
|
|
|
|
RUN apt-get update --fix-missing && apt-get install -y ca-certificates openssh-client curl gnupg docker.io
|
|
|
|
RUN install -m 0755 -d /etc/apt/keyrings
|
|
RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /etc/apt/keyrings/docker.gpg
|
|
RUN chmod a+r /etc/apt/keyrings/docker.gpg
|
|
RUN echo \
|
|
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian \
|
|
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
|
|
tee /etc/apt/sources.list.d/docker.list > /dev/null
|
|
|
|
RUN apt-get update --fix-missing && apt-get install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
|
|
|
|
COPY *.sh .
|
|
COPY app/ .
|
|
|
|
RUN rm -rf /root/.ssh
|
|
RUN ln -s /shared/ssh /root/.ssh
|
|
RUN mkdir -p /etc/docker/certs.d/registry:4443 && ln -s /shared/certs/domain.crt /etc/docker/certs.d/registry:4443/ca.crt
|
|
|
|
RUN git config --global user.email "deployer@example.com"
|
|
RUN git config --global user.name "Deployer"
|
|
RUN git init && echo ".env" >> .gitignore && git add . && git commit -am "Initial version"
|
|
|
|
HEALTHCHECK --interval=1s CMD pgrep sleep
|
|
|
|
CMD ["./boot.sh"]
|