原始文件

networks:
  default:
    ipam:
      config:
        - gateway: 10.255.3.1
          subnet: 10.255.3.0/24
      driver: default
services:
  authorization:
    depends_on:
      - database
    environment:
      ENABLE_AUTHORIZATION: 'false'
      JDBC_URL: jdbc:h2:tcp://database:1521/uaa;DATABASE_TO_UPPER=false;DB_CLOSE_DELAY=-1
      SEAHORSE_ADMIN_EMAIL: [email protected]
    image: seahorse-authorization:01aa3905657af84c5dd2db1b9932ebaddd446df2

现在需要将seahorse-authorization这段替换为quay-mirror.qiniu.com/deepsense_io/seahorse-authorization:1.4.3

脚本如下

#!/bin/bash
#author:jack
#date:20190813
test01=`ack seahorse-authorization docker-compose.yml | awk -F ": " '{print $2 $3}'`
test02=quay-mirror.qiniu.com/deepsense_io/seahorse-authorization:1.4.3
sed "s#$test01#$test02#g" docker-compose.yml
sed 's/127.0.0.1/0.0.0.0/g' docker-compose.yml

test01是一个随机数组 test02 是一串字符
所以test02也采取为传参的形式