Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to wait for docker before starting #1705

Merged
merged 3 commits into from
Apr 3, 2022
Merged

Add option to wait for docker before starting #1705

merged 3 commits into from
Apr 3, 2022

Conversation

c-w
Copy link
Contributor

@c-w c-w commented Apr 2, 2022

What does this pull request do?

This pull request adds a new configuration option DOZZLE_WAIT_FOR_DOCKER which if set will defer the server start until the connection to docker is healthy.

Why is this useful?

In some environments, the docker connection isn't via a socket file but instead via tcp, for example if we're connecting to a remote docker host or if we're using a proxy to only allow selective access to docker APIs for security reasons. In these scenarios, the docker host may or may not be ready to serve requests at the time that dozzle starts. To simplify deployments in such an environment, it's very useful if dozzle can "self heal" and only start talking to the docker host once the docker host is ready for connections.

Of course it would also be possible to perform an external health check before starting the dozzle container, but this adds non-trivial complexity to the orchestration especially as the the dozzle container doesn't contain a shell so we couldn't for example override the entrypoint to a loop like sh -c "while ! exec /dozzle; do sleep 5; done". Other tools that talk to the docker host (e.g. Traefik) implement this sort of "self heal" mechanism so I believe it would be neat if dozzle could also do this, especially as the added code complexity is quite minor.

How can I test these changes?

Create a docker-compose file that defines dozzle and the docker socket proxy:

version: "2.3"

services:

  dozzle:
    build: .
    environment:
      DOZZLE_NO_ANALYTICS: "1"
      DOZZLE_WAIT_FOR_DOCKER_SECONDS: "120"
      DOCKER_HOST: "tcp://docker-proxy:2375"
    ports:
      - "8080:8080"

  docker-proxy:
    image: tecnativa/docker-socket-proxy
    environment:
      CONTAINERS: "1"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro

Now start dozzle via docker-compose up --build dozzle and you will notice that the server waits to start up since the docker connection can't be established. Now start the docker socket proxy via docker-compose up -d docker-proxy and you will notice that dozzle now starts the server.

@c-w
Copy link
Contributor Author

c-w commented Apr 2, 2022

Note that I had to push a change to the dev.yml Github Action as it was failing for me since pull requests from forks don't have access to the secrets. Instead of failing the action, we now skip it for any pull request from a fork.

@amir20
Copy link
Owner

amir20 commented Apr 2, 2022

Interesting use case. I never had it happen. But it makes sense. I'll review later.

main.go Show resolved Hide resolved
@c-w c-w requested a review from amir20 April 3, 2022 01:57
@amir20 amir20 merged commit 76f8380 into amir20:master Apr 3, 2022
@c-w c-w deleted the retry-start branch April 3, 2022 17:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants