1

When I would like to update an app at the moment, docker-compose down, the version in the docker-compose.yaml is changed, subsequently the app is started and the latest version is running.

Now I would like to update it automatically. It it possible to update the version by passing a variable?

Workaround

At the moment I use sed to update the docker-compose file, but I wonder whether there is an easier approach.

030
  • 13,235
  • 16
  • 74
  • 173

2 Answers2

3

Another way to execute the @golfNintyNine answer is putting inside docker-compose.yml the environment variable:

serviceName:
image: "imageName:${VERSION}"

And then executing simply:

$ VERSION=2 docker-compose up

Also you can put all together inside script file like this:

#!/bin/bash

function usage {
    cat << EOF >&2
Version argument is required, please use -v or --version.
EOF
    exit 1
}


OPTS=`getopt -o v: -l version: -- "$@"`


if [ $? != 0 ] ; then usage ; fi

eval set -- "$OPTS"

while true; do
    case "$1" in
        -v | --version ) export VERSION="$2"; shift 2;;
        -- ) shift; break ;;
    esac
done

if [ -z $VERSION ]
then
    usage
fi

docker-compose up
wolmi
  • 248
  • 2
  • 8
2

You could use environment variables e.g.:

export VERSION=2

docker-compose.yml:

...
  serviceName:
    image: "imageName:${VERSION}"
  ....
anstue
  • 176
  • 1
  • 5