title: sed to replace docker image tag in docker-compose
body: <p>We are using GitLab for CI-CD and our applications are run as docker-containers inside EC2 instances and use ECR as the registry. I have a problem with this approach when it comes to the deployment stage. I want <code>docker-compose.yml</code> to pick up the image tagged with the current branch from ECR. Hence I use <code>$CI_COMMIT_BRANCH</code> like this :</p>
  <p><code>sudo docker-compose pull | sed &quot;s/$VERSION/$CI_COMMIT_BRANCH/g&quot;</code></p>
  <p>I know the syntax is incorrect and <code>$VERSION</code> gets replaced permanently by the branch name. So, when next time I do <code>sudo docker-compose pull</code> there's no <code>$VERSION</code> to replace &amp; deployment stage will stop.</p>
  <p>Our ECR images will have a path like this: <code>xxxxxxxxxxxx.dkr.ecr.ap-south-1.amazonaws.com/ground-zero/x:$VERSION</code> (inside <code>docker-compose.yml</code>)</p>
  <p>How to use <code>sed</code> correctly to search for <code>code-ground &amp; :</code> because they are common for every microservice in the ECR path.</p>