4 ms·
How do you automate the updating of images on Docker Swarm?
by lucaspiller 9y ago
How do you automate the updating of images on Docker Swarm?
- snorremd 9y agoI can't talk for the original poster, but I also deploy containers from Gitlab Registry via Gitlab CI pipelines and just use the standard docker swarm commands. So updating the image digest (version) of a service is as simple as running a shell command in a job in a deploy stage in your gitlab ci pipeline: docker service update --image <some-image:version> --with-registry-auth <some-service> Simplest example would be a job definition like this: https://pastebin.com/KsG0cDzR https://pastebin.com/KsG0cDzR This job would have to be preceded by building the new docker image you are going to update to of course.
- conradk 9y agoWhat I've found to work well is to push images to your registry with a different tag for each release. For instance, you have "web:1.0" running in production and want to update? Create a "web:1.1" image, push it to your registry and in Docker Swarm, point your "web" service to the "web:1.1" image instead of "web:1.0".
- raarts 9y agoI define a docker stack .yml file, and have GitLab CI run docker stack deploys.
- coding123 9y agoI do this: docker build -t $APPNAME:$timestamp . OUTPUT="$(docker service inspect -f '{{.Spec.Name}}' sv-$APPNAME || true)" if [ "$OUTPUT" == "" ]; then # Service does not exist echo "Creating service" docker service create --update-delay 5s \ --publish $PUBPORT:8080 --replicas 2 \ --mount type=bind,source=$(cd ../images; pwd),target=/images,readonly=true \ --mount type=bind,source=$(cd ../processed_images; pwd),target=/app/images \ --mount type=bind,source=$(cd ..; pwd)/config.json,target=/config.json,readonly=true \ --mount type=bind,source=$(cd ~/.aws; pwd),target=/root/.aws,readonly=true \ --name sv-$APPNAME $APPNAME:$timestamp else # Service exists echo "Updating service" docker service update --image $APPNAME:$timestamp sv-$APPNAME I haven't looked in a while, but it would be nice if they had some kind of "upstall" (update/install) kinda like upsert (update/insert) in CRUD land.
- acejam 9y agoThis is the easiest part, you just call: docker service update --image $image_name:$new_sha $service_name and Swarm handles the rest. You can even pass in rolling update options, so the container updates are staggered. Put this into a simple bash script that only runs when the current branch is master. (Because your CI is building every branch to give you fast feedback, right?) In the case of CircleCI or TravisCI, that can be done with something like: if [ "${CIRCLE_BRANCH}" == "master" ]; then