0

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.

Nanne
  • 64,065
  • 16
  • 119
  • 163
gleX
  • 595
  • 2
  • 8
  • 22
  • Could it just be your images? If the images do not actually start somethign (e.g. they have nothing to run, or whatever runs stops) then the logical thing for them to do is to stop. – Nanne Jan 30 '17 at 11:25
  • OK. The images are in my machine, I created that images and when I define an image with a name that does not exist, docker-compose give me a message with the no existing images. – gleX Jan 30 '17 at 11:28
  • I'm not sure what you mean. Above looks perfectly sane: read e.g. http://stackoverflow.com/questions/28212380/why-docker-container-exits-immediately . it could very well be your images don't do anything, so docker-compose starts them as you requested, but as they don't do anything, they exit (with status `0`, which is 'no error) – Nanne Jan 30 '17 at 11:31
  • Sorry. I mean that this are my own images and when I define in the docker-compose.yml an image that does not exist, docker-compose give an error. – gleX Jan 30 '17 at 11:40
  • If a run this images with the command "docker run ..." they run perfectly and with "docker start" the state is "up", so, the images exist. – gleX Jan 30 '17 at 11:42
  • OK. I guess I get what you mean with images don't do anything, but I don't understand, because I put in the docker-compose.yml file the execution of an script that start a server (and the state of the container is "up") but after the startup script of the server end, the container change the state to Exit. It's looks that I need to use a keepalive to mantain the container with state "up" – gleX Jan 30 '17 at 15:49
  • The usual route is to not start a server in the background (daemonise), but just start it. – Nanne Jan 30 '17 at 19:40
  • This is the result without daemonize is the same, the server that are into the containers started but the state of the instance is "Exit 0", looks like the servers started correctly but I don't know how to attach. Maybe the problem is that I don't know how to attach, I tried with "docker attach xxxxx" – gleX Jan 31 '17 at 12:04
  • There is one thing that I'm curious, but the hostname in all the instances of the same container has the same hostname, I expected a incremental hostname. – gleX Jan 31 '17 at 12:45
  • what command do these things have in de dockerfile? – Nanne Jan 31 '17 at 13:08
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/134482/discussion-between-nanne-and-glex). – Nanne Jan 31 '17 at 13:08

1 Answers1

1

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.

Nanne
  • 64,065
  • 16
  • 119
  • 163