Hey folks! I'm trying to automate the process of pulling new Docker image versions from Docker Hub onto my VPS where my API runs. I have a CI/CD pipeline that builds and pushes new versions to my private Docker Hub repository based on the commit tags, like "api-image:dev-v1.0.0". What's the best way to do this securely and smoothly? I'm thinking maybe a bash script or something similar? I'd love to hear your usual methods!
5 Answers
There are a few ways to approach this, depending on your setup. If you’re using Kubernetes, tools like ArgoCD or Flux are great for GitOps. For simple Docker setups, you can log into your VPS and pull from there using a CI script or even an Ansible role. Another neat option is to set up a Docker Hub webhook that triggers a specific API endpoint on your app, which then runs a script to update your images. It really depends on whether you prefer a pull or push setup and how much oversight you want during deployments.
I prefer using a webhook approach. Docker Hub allows you to add a webhook that triggers a script whenever there’s a new push, automating the pulling of the latest images!
Have you considered using Watchtower? It’s a handy tool that automatically updates your containers when new images are available.
I use the appleboy/ssh-action for executing Docker Stack deployments on my VPS. It does require SSH credentials, so you’ll want to make sure you're comfortable with that setup.
I’ve got local GitHub Actions on my VPS that handle compilation and such. I have a workflow set up in my .github folder that pulls the image and restarts the Docker stack. It’s convenient because I can run tests before deploying if needed.
Related Questions
Can't Load PhpMyadmin On After Server Update
Redirect www to non-www in Apache Conf
How To Check If Your SSL Cert Is SHA 1
Windows TrackPad Gestures