0

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.

1

You could use environment variables e.g.:

export VERSION=2

docker-compose.yml:

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

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.