【问题标题】:fetch docker container ID/Name from docker image and rename that container从 docker 镜像中获取 docker 容器 ID/名称并重命名该容器
【发布时间】:2021-08-20 07:47:53
【问题描述】:

我想要实现的是重命名 docker 容器。众所周知,AWS ECS 容器名称是动态的,因此我们必须使用 docker 映像来获取容器 ID 或名称。 所以我想从图像中获取/获取容器 ID,然后将其重命名为我的选择。 我正在使用不支持对 docker 容器进行常量命名的 AWS ECS,因此每当它启动具有唯一名称的容器时,我都想将其重命名为我选择的名称。

【问题讨论】:

    标签: docker amazon-ecs


    【解决方案1】:

    回答我自己的问题。我做了一个解决方法,这就像一个魅力! 创建一个名为 setDockerContainerName.sh

    的文件
    #!/bin/bash
    
    # list docker container's and then filter with image name to grep container ID, through awk assign continerID a variable name testVar and store this value in file testVar.txt 
    docker ps | grep '<imageNameHere>' | awk '{print "testVar=" $1 }' > testVar.txt
    
    # export values in the given file
    while read LINE; do export "$LINE"; done < ./testVar.txt
    
    # rename docker container to choose one
    docker rename $testVar newContainerName
    

    【讨论】:

      猜你喜欢
      • 2019-06-03
      • 1970-01-01
      • 2015-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-14
      • 2020-10-04
      • 1970-01-01
      相关资源
      最近更新 更多