简体   繁体   English

容器名称的Docker-Compose问题

[英]Docker-Compose Issue with container name

I have created a docker image with required packages. 我已经使用必需的软件包创建了一个docker镜像。 I have run the docker image specifying the host and guest port along with the required volume mounting Example: 我已经运行了指定主机和来宾端口以及所需的卷安装示例的docker映像:


sudo docker run -it --name CONTAINERNAME -v /host:/guest -p
hostportno:guestportno

My container is up and running fine. 我的容器已启动并且运行良好。
I am trying to migrate my container to a new docker image using docker-compose . 我正在尝试使用docker-compose将容器迁移到新的Docker映像。
I have created docker-compose.yml file and specified the required parameters as shown below: 我已经创建了docker-compose.yml文件并指定了所需的参数,如下所示:

image: test1
ports
  - "1234:123"
  - "2000:223"  
volumes:
  - /home:/test  
  -container_name: dockercomposetest  
working_dir: /test  
command: /bin/bash

I am unable to migrate it using docker-compose. 我无法使用docker-compose迁移它。
I am getting issue as stated below: 我遇到如下问题:

Conflict. The name "test" is already in use by container eeedac72bb25.
You have to delete (or rename) that container to be able to reuse that
name.

Work around currently is I have to stop and remove the container and perform docker-compose up . 当前的解决方法是我必须停止并移除容器并执行docker-compose up
Can I not restart/migrate a container using docker-compose with same name as I have started in normal docker run process. 我是否可以使用与正常docker run过程中启动的名称相同的名称使用docker-compose重新启动/迁移容器。

No, you can't have two containers with the same name. 不可以,您不能有两个名称相同的容器。 You'll have to pick a different name for the container_name field. 您必须为container_name字段选择其他名称。 The previous container needs to be removed before you can re-use the name. 您必须先删除以前的容器,然后才能重新使用该名称。

If you wanted Compose to treat the container as if it had created it, you have to set the container labels as Compose does. 如果希望Compose将容器视为已创建容器,则必须像Compose一样设置容器标签。 The easiest way to find these would be to have compose create a container (probably by removing the container_name field), then using docker inspect to view the labels. 查找这些内容的最简单方法是compose创建一个容器(可能通过删除container_name字段),然后使用docker inspect查看标签。

You can check if --force-recreate would help: 您可以检查--force-recreate是否有帮助:

 docker-compose up --force-recreate  

From the docker-compose up man page : docker-compose up手册页中

If you want to force Compose to stop and recreate all containers, use the --force-recreate flag. 如果要强制Compose停止并重新创建所有容器,请使用--force-recreate标志。

 --force-recreate  

Recreate containers even if their configuration and image haven't change 重新创建容器,即使它们的配置和映像没有改变

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM