Can't update version tag in docker compose file with sed

Viewed 1243

I have the following yml file:

api:
    restart: always
    image: docker.registry-test.com/api:3.4.1

api-server:
    restart: always
    image: docker.registry-test.com/api-server

I'm running sed to update the version of image to 3.4.2 in api section:

sed -i "/^[[:space:]]*api:/,/^[^[:space:]]/ s/\(docker.registry-test.com\/api\).*$/\1:3.4.2/" docker.yaml

But it also changes the the image name and version in api-server section. I'm trying to make a change avoid from changing second section.

2 Answers

Just made a small change(moved colon):

sed -i "/^[[:space:]]*api:/,/^[^[:space:]]/ s/\(docker.registry-test.com\/api:\).*$/\13.4.2/" docker.yaml

this should work in GNU sed.

ubuntu$ sed -E 's/(api:)([0-9.]+)/api:3\.4\.2/g' text.txt
api:
    restart: always
    image: docker.registry-test.com/api:3.4.2

api-server:
    restart: always
    image: docker.registry-test.com/api-server

Let me know if it works for you.

Related