nmagerko
nmagerko

Reputation: 6794

Keeping Docker Containers Current

Let's say that I have several Docker containers. Each is serving code that was originally pulled from a remote Git repository when the container was started. However, now some of the containers are serving code that is behind the remote master branch. I want to get all of them up-to-date.

I realize that I could probably run docker exec -it [container_id] bash and then manually git pull inside of each of my containers, but that does not seem like a very scalable or practical option.

Is there an existing method for automating the code-pulls of my Docker containers? Are webhooks the proper way of going about this?

Upvotes: 1

Views: 284

Answers (1)

Abdullah Jibaly
Abdullah Jibaly

Reputation: 54790

You can use web hooks assuming that you have a reachable endpoint. I prefer building new docker images when your repo is updated but going with your approach you can consider something like:

  1. Let's call your containers A, B, and C.
  2. Setup a new container W that exposes the web hook, and mounts volumes for A, B, and C. Your git packages will be cloned into those volumes.
  3. docker run A, B, and C with --volumes-from W
  4. When W receives an update, it does a git pull on the appropriate package, automatically updating the code that the container sees.
  5. W might need to send a restart signal to the container as appropriate.

Upvotes: 1

Related Questions