Search code examples
dockerdocker-compose

Docker-compose does not start containers


I'm new with docker-compose. I have a problem when I use the command "docker-compose up -d" to start a multi-container application what should start the containers with the status "up" but all the time a execute the command the status is "Exit", I'm not sure if I'm doing something wrong, this is my docker-compose.yml file

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

example run:

 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

Please, can anybody help me? docker-compose version 1.13.


Solution

  • I think I got it: you are overriding the command you give in the dockerfile because you have this line in each of the services

    command: hostname
    

    so the only command you give is "hostname", which is actually what is run.

    If you run an image with docker, you are probably running a completely different command!

    If this is a linux based image, 'hostname' will just print the hostname and then exit. So then the command is stopped which logically will result in a stopped container (exit 0)

    Remove the command-override so the containers actually run their respective commands.