Jump to content

Best way to automatically update docker container to latest image version from a Github action?

GNUGradyn

Hello. This is more of a DevOps question so hopefully this is the right category.

I have a server that I deploy many of my personal projects to. These projects are stored & built on Github and deployed automatically via Github actions. I originally did this via the SSH Deploy action, which would rsync the updated application to the server and then restart its systemd unit. However I have decided to try and containerize all my projects for easier management. I created a private container registry and this workflow which builds the app and publishes it to the private registry. This is all well and good but then I have to manually log into the server and recreate the container to get the latest version actually deployed. I am trying to automate this via a Github action.

 

I am aware of Watchtower, but my understanding of it is it just checks in with the registry periodically to make sure it is on the latest version. This is not ideal for me because I want the container to be updated immediately. If watchtower has some sort of webhook I can hit to hint at it from Github that the image has been updated, that would be cool. If not or if there is a better approach, let me know your ideas.

 

Thanks in advance

Link to comment
Share on other sites

Link to post
Share on other sites

I would use docker compose to run the service, then all it takes to update is to do

docker compose pull
docker compose up -d

in the directories that contain a docker-compose.yml. (Note: If you have an older version of docker, docker-compose is/was a script, now it's built in). This should be easy enough to automate through SSH.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

8 hours ago, Eigenvektor said:

I would use docker compose to run the service, then all it takes to update is to do

docker compose pull
docker compose up -d

in the directories that contain a docker-compose.yml. (Note: If you have an older version of docker, docker-compose is/was a script, now it's built in). This should be easy enough to automate through SSH.

Thank you. Do you have a recommendation for how to execute this over ssh via a github action?

Link to comment
Share on other sites

Link to post
Share on other sites

1 hour ago, GNUGradyn said:

Thank you. Do you have a recommendation for how to execute this over ssh via a github action?

I ended up using appleboy/ssh-action

Link to comment
Share on other sites

Link to post
Share on other sites

Update: I also found an easier way to do this. Portainer has a websocket feature. It simply gives you a URL you can hit with a POST request to trigger it to update.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×