Docker-compose不会启动容器

时间:2017-01-30 11:02:33

标签: docker docker-compose

我是docker-compose的新手。当我使用命令" docker-compose up -d"启动一个多容器应用程序什么应该启动容器状态" up"但是一直执行命令,状态是"退出",我不确定我是否做错了,这是我的docker-compose.yml文件

version: '3'

services:   catalog:
     image: ciscatalog
     hostname: catalogHost
     command: hostname
     volumes:
       - /home/docker:/opt/host

  container:
    image: dis/ciscontainer
    hostname: containerHost
    command: hostname
    volumes:
      - /home/docker:/opt/host


  inbound:
    image: dsi/cisinbound
    hostname: inboundHost
    depends_on:
      - catalog
    links:
      - catalog
    command: hostname
    volumes:
      - /home/docker:/opt/host


  outbound:
    image: dsi/cisoutbound
    hostname: outboundHost
    depends_on:
      - catalog
    links:
      - catalog
    command: hostname
    volumes:
      - /home/docker:/opt/host

示例运行:

 root@docker1:/home/docker/DSI# docker-compose scale catalog=3 container=4  inbound=1   outbound=1
    Creating and starting dsi_catalog_1 ... done
    Creating and starting dsi_catalog_2 ... done
    Creating and starting dsi_catalog_3 ... done
    Creating and starting dsi_container_1 ... done
    Creating and starting dsi_container_2 ... done
    Creating and starting dsi_container_3 ... done
    Creating and starting dsi_container_4 ... done
    Creating and starting dsi_inbound_1 ... done
    Creating and starting dsi_outbound_1 ... done
root@docker1:/home/docker/DSI# docker-compose up -d
Starting dsi_container_4
Starting dsi_catalog_3
Starting dsi_catalog_1
Starting dsi_container_3
Starting dsi_catalog_2
Starting dsi_container_1
Starting dsi_outbound_1
Starting dsi_inbound_1
Starting dsi_container_2
   root@docker1:/home/docker/DSI# docker-compose ps
         Name         Command    State    Ports
    -------------------------------------------
    dsi_catalog_1     hostname   Exit 0
    dsi_catalog_2     hostname   Exit 0
    dsi_catalog_3     hostname   Exit 0
    dsi_container_1   hostname   Exit 0
    dsi_container_2   hostname   Exit 0
    dsi_container_3   hostname   Exit 0
    dsi_container_4   hostname   Exit 0
    dsi_inbound_1     hostname   Exit 0
    dsi_outbound_1    hostname   Exit 0

拜托,有人可以帮帮我吗? docker-compose版本1.13。

1 个答案:

答案 0 :(得分:1)

我想我明白了:你重写了你在dockerfile中给出的命令,因为你在每个服务中都有这一行

command: hostname

所以你给出的唯一命令是“hostname”,这实际上就是运行的命令。

如果使用docker运行图像,则可能运行完全不同的命令!

如果这是基于linux的图像,'hostname'将只打印主机名然后退出。因此,命令停止,逻辑上将导致停止的容器(退出0)

删除命令覆盖,以便容器实际运行各自的命令。