使用docker-compose创建容器会删除另一个已在运行的容器

时间:2017-11-10 11:28:02

标签: image docker docker-compose containers

我正在尝试使用基于2个不同图像的docker-compose命令启动2个单独的容器。

一个图像(工作)基于“开发”中的代码。第二个图像(缺点)图像由当前处于“合并”级别的代码创建。

启动第一个容器时,一切似乎都没问题。

enter image description here

以上图片详情如下:

工作目录:〜/ apps / django.work / extraction / docker-compose.yml

version: '3'

services:
  db:
    image: postgres
    container_name: postgres-work           
  web:
    build: .
    image: apostx-cc-backoffice-work        
    container_name: cc-backoffice-work      
    command: python3 backendworkproj/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "7350:8000"
    depends_on:
      - db

执行:〜/ apps / django.work。/ extract $ docker-compose up --no-deps -d web

Creating network "extraction_default" with the default driver
Creating cc-backoffice-work ...
Creating cc-backoffice-work ... done

执行:〜/ apps / django.work / extraction $ docker container ls

CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                    NAMES
39185f36941a        apostx-cc-backoffice-work   "python3 backendwo..."   8 seconds ago       Up 7 seconds        0.0.0.0:7350->8000/tcp   cc-backoffice-work
dede5cb1966a        jarkt/docker-remote-api     "/bin/sh -c 'socat..."   2 days ago          Up 2 days           0.0.0.0:3080->2375/tcp   dock_user_display_remote

但是,当我使用第二个目录编译并启动另一个图像时,一些奇怪的事情开始发生:

enter image description here

同样,更多细节如下:

CONS DIRECTORY:〜/ apps / django.cons / extraction / docker-compose.yml

version: '3'

services:
  db:
    image: postgres
    container_name: postgres-cons         
  web:
    build: .
    image: apostx-cc-backoffice-cons      
    container_name: cc-backoffice-cons    
    command: python3 backendworkproj/manage.py runserver 0.0.0.0:8000
    volumes:
      - .:/code
    ports:
      - "7450:8000"
    depends_on:
      - db

执行:〜/ apps / django.cons / extraction $ docker-compose up --no-deps -d web

Recreating cc-backoffice-work ...
Recreating cc-backoffice-work
Recreating cc-backoffice-work ... done

执行:〜/ apps / django.cons / extraction $ docker container ls

CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                    NAMES
f942f84e567a        apostx-cc-backoffice-cons   "python3 backendwo..."   7 seconds ago       Up 6 seconds        0.0.0.0:7450->8000/tcp   cc-backoffice-cons
dede5cb1966a        jarkt/docker-remote-api     "/bin/sh -c 'socat..."   2 days ago          Up 2 days           0.0.0.0:3080->2375/tcp   dock_user_display_remote

问题

为什么第一个容器在我启动第二个容器时会被取代?如果是由于某种缓存问题,如何在第二次运行docker-compose之前重新初始化/清理/清除缓存?我在这里错过了什么吗?

TIA

更新 - 我执行了以下操作:

  
      
  1. 使用“docker container rm -f”
  2. 删除旧容器   

-

  
      
  1. 启动了“工作”(即开发)容器
  2.   

执行:〜/ apps / django.work.ccbo.thecontractors.club / extraction $ docker-compose --verbose up --no-deps -d web>& the_results_are_here

执行:〜/ apps / django.work.ccbo.thecontractors.club / extraction $ docker container ls

CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                    NAMES
61d2e9ccbc28        apostx-cc-backoffice-work   "python3 backendwo..."   4 seconds ago       Up 4 seconds        0.0.0.0:7350->8000/tcp   work-cc-backoffice
dede5cb1966a        jarkt/docker-remote-api     "/bin/sh -c 'socat..."   3 days ago          Up 3 days           0.0.0.0:3080->2375/tcp   dock_user_display_remote
9b4b8b462fcb        wmaker-test-officework      "catalina.sh run"        11 days ago         Up 11 days          0.0.0.0:7700->8080/tcp   testBackOfficeWork.2017.10.30.04.20.01
ad5fd0592a07        wmaker-locl-officework      "catalina.sh run"        11 days ago         Up 11 days          0.0.0.0:7500->8080/tcp   loclBackOfficeWork.2017.10.30.04.20.01
7bc9d7f94828        wmaker-cons-officework      "catalina.sh run"        11 days ago         Up 11 days          0.0.0.0:7600->8080/tcp   consBackOfficeWork.2017.10.30.04.20.01
  
      
  1. 看到它看起来没问题,启动容器“cons”(合并)
  2.   

执行:〜/ apps / django.cons.ccbo.thecontractors.club / extraction $ docker-compose --verbose up --no-deps -d web>& the_results_are_here

执行:〜/ apps / django.cons.ccbo.thecontractors.club / extraction $ docker container ls

CONTAINER ID        IMAGE                       COMMAND                  CREATED             STATUS              PORTS                    NAMES
0fb24fc45877        apostx-cc-backoffice-cons   "python backendwor..."   5 seconds ago       Up 4 seconds        0.0.0.0:7450->8010/tcp   cons-cc-backoffices
dede5cb1966a        jarkt/docker-remote-api     "/bin/sh -c 'socat..."   3 days ago          Up 3 days           0.0.0.0:3080->2375/tcp   dock_user_display_remote
9b4b8b462fcb        wmaker-test-officework      "catalina.sh run"        11 days ago         Up 11 days          0.0.0.0:7700->8080/tcp   testBackOfficeWork.2017.10.30.04.20.01
ad5fd0592a07        wmaker-locl-officework      "catalina.sh run"        11 days ago         Up 11 days          0.0.0.0:7500->8080/tcp   loclBackOfficeWork.2017.10.30.04.20.01
7bc9d7f94828        wmaker-cons-officework      "catalina.sh run"        11 days ago         Up 11 days          0.0.0.0:7600->8080/tcp   consBackOfficeWork.2017.10.30.04.20.01
  
      
  1. 同样,名称:work-cc-backoffice已被名称取代:cons-cc-backoffices - work-cc-backoffice现已完全消失。
  2.   

-

  
      
  1. 查看文件the_results_are_here(在第二次运行中)以查看是否可以找到任何内容
  2.   
[... snip ...]

compose.cli.command.get_client: docker-compose version 1.17.1, build 6d101fb
docker-py version: 2.5.1
CPython version: 2.7.13
OpenSSL version: OpenSSL 1.0.1t  3 May 2016
compose.cli.command.get_client: Docker base_url: http+docker://localunixsocket
compose.cli.command.get_client: Docker version: KernelVersion=4.4.0-72-generic, Arch=amd64, BuildTime=2017-09-26T22:40:56.000000000+00:00, ApiVersion=1.32, Version=17.09.0-ce, MinAPIVersion=1.12, GitCommit=afdb6d4, Os=linux, GoVersion=go1.8.3
compose.cli.verbose_proxy.proxy_callable: docker info <- ()
compose.cli.verbose_proxy.proxy_callable: docker info -> {u'Architecture': u'x86_64',

[... snip ...]

compose.cli.verbose_proxy.proxy_callable: docker inspect_network <- (u'extraction_default')
compose.cli.verbose_proxy.proxy_callable: docker inspect_network -> {u'Attachable': True,
 u'ConfigFrom': {u'Network': u''},
 u'ConfigOnly': False,
 u'Containers': {u'61d2e9ccbc28bb2aba918dc24b5f19a3f68a06b9502ec1b98e83dd947d75d1be': {u'EndpointID': u'e19696ccf258a6cdcfcce41d91d5b3ebcb5fffbce4257e3480ced48a3d7dcc5c',
                                                                                       u'IPv4Address': u'172.20.0.2/16',
                                                                                       u'IPv6Address': u'',
                                                                                       u'MacAddress': u'02:42:ac:14:00:02',
                                                                                       u'Name': u'work-cc-backoffice'}},
 u'Created': u'2017-11-10T09:56:22.709914332Z',

 u'Driver': u'bridge',
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=False, filters={u'label': [u'com.docker.compose.project=extraction', u'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- (u'61d2e9ccbc28bb2aba918dc24b5f19a3f68a06b9502ec1b98e83dd947d75d1be')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {u'AppArmorProfile': u'docker-default',
 u'Args': [u'backendworkproj/manage.py', u'runserver', u'0.0.0.0:8000'],
 u'Config': {u'AttachStderr': False,
             u'AttachStdin': False,
             u'AttachStdout': False,
             u'Cmd': [u'python3',
                      u'backendworkproj/manage.py',
                      u'runserver',
                      u'0.0.0.0:8000'],
             u'Domainname': u'',
...
compose.cli.verbose_proxy.proxy_callable: docker containers <- (all=True, filters={u'label': [u'com.docker.compose.project=extraction', u'com.docker.compose.service=web', u'com.docker.compose.oneoff=False']})
compose.cli.verbose_proxy.proxy_callable: docker containers -> (list with 1 items)
compose.cli.verbose_proxy.proxy_callable: docker inspect_container <- (u'61d2e9ccbc28bb2aba918dc24b5f19a3f68a06b9502ec1b98e83dd947d75d1be')
compose.cli.verbose_proxy.proxy_callable: docker inspect_container -> {u'AppArmorProfile': u'docker-default',
  

对我而言,程序似乎正在尝试进行一些初始化   通过寻找已经启动并运行的容器(?)参见图片。   下面。如何改变这种行为

enter image description here

1 个答案:

答案 0 :(得分:1)

来自@mikeyjk的回答解决了这个问题。

  

不用担心。我想知道你是否给每个服务一个独特的名字,重新运行   作曲家建立,问题是否仍然存在。我会尝试复制   今天如果没有人可以解决它