Answers: <p>You could use environment variables e.g.:</p>
  
  <pre><code>export VERSION=2
  </code></pre>
  
  <p>docker-compose.yml:</p>
  
  <pre><code>...
    serviceName:
      image: "imageName:${VERSION}"
    ....
  </code></pre>
  
Answers: CC BY-SA 3.0
Answers: 2018-03-07T12:21:54.393Z
Answers: 2018-03-07T12:21:54.393Z
Answers: anstue
Answers: <p>Another way to execute the @golfNintyNine answer is putting inside docker-compose.yml the environment variable:</p>
  
  <pre><code>serviceName:
  image: "imageName:${VERSION}"
  </code></pre>
  
  <p>And then executing simply:</p>
  
  <pre><code>$ VERSION=2 docker-compose up
  </code></pre>
  
  <p>Also you can put all together inside script file like this:</p>
  
  <pre><code>#!/bin/bash
  
  function usage {
      cat &lt;&lt; EOF &gt;&amp;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
  </code></pre>
  
Answers: CC BY-SA 3.0
Answers: 2018-03-07T14:43:19.830Z
Answers: 2018-03-07T14:43:19.830Z
Answers: wolmi
Body: <p>When I would like to update an app at the moment, <code>docker-compose down</code>, the version in the <code>docker-compose.yaml</code> is changed, subsequently the app is started and the latest version is running.</p>
  
  <p>Now I would like to update it automatically. It it possible to update the version by passing a variable?</p>
  
  <p><strong>Workaround</strong></p>
  
  <p>At the moment I use <code>sed</code> to update the docker-compose file, but I wonder whether there is an easier approach.</p>
  
Tags: <docker-compose>
Title: How to pass the version to docker-compose?
UserDisplayName: 030
ThreadText: # How to pass the version to docker-compose?
  
  (Asked by: username_0 on 2018-03-04)
  
  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.
  
  **Tags:** docker-compose
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2018-03-07. Score: 2 | Accepted answer
  
  You could use environment variables e.g.:
  
  ```
  export VERSION=2
  
  ```
  
  docker-compose.yml:
  
  ```
  ...
    serviceName:
      image: "imageName:${VERSION}"
    ....
  
  ```
  
  
  ---
  
  ### Answer by username_2 on 2018-03-07. Score: 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
  
  ```
  
  
  ---
  
  