Compose: Container stops immediately with docker-compose but runs fine with Docker.

Created on 11 Jul 2017  路  20Comments  路  Source: docker/compose

I have two services and each service calls dockerfile which has microsoft/windowsservercore as a base image.
When I run docker-compose up on windows, the containers are getting stopped immediately however same yaml file on linux keeps containers running. is there any known issue on windows?

my docker-compose.yml file is:

version: '3'

networks:
  default:
    external:
      name: nat

services:
  awi-service:
    env_file:
      - awi-box.env
    image: awi-box:12.0.0
    ports:
    - 8080:8080
    depends_on:
    - ae-service


  ae-service:
    env_file:
      - ae-box.env
    image: ar-box:12.0.0
    ports:
    -  2217:2217
    -  2218:2218
grouwindows-server kinquestion

Most helpful comment

After I have added stdin_open: true and tty: true to compose file, I can see the container is up and running.

We can close this issue unless there is any other solution available for this.

All 20 comments

Did you check the logs of your services? What is their exit code? Does docker-compose --verbose up give you any additional information?

Sorry for the delay in reply. The exit code is 0. Both the containers are getting exited with code 0. When I run containers for the images given above in compose file manually using docker run then those containers remain up and running.

D:\Compose_Test>docker logs --details 9ce72c60d698

 Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
 -------  ------    -----      -----     ------     --  -- -----------
      39       4     3812       3124       0.02    960  29 cmd
 Microsoft Windows [Version 10.0.14393]
 (c) 2016 Microsoft Corporation. All rights reserved.

 C:\tomcat7\webapps\awi\config>


D:\Compose_Test>docker logs --details 88ec90b8142b

 Handles  NPM(K)    PM(K)      WS(K)     CPU(s)     Id  SI ProcessName
 -------  ------    -----      -----     ------     --  -- -----------
       0       1      276         64       0.00   6524  28 UCYBSMgr
 Microsoft Windows [Version 10.0.14393]
 (c) 2016 Microsoft Corporation. All rights reserved.

 C:\automic\ServiceManager\bin>

Looking at above container log, everything looks fine.

This is usually happens when the command does not have any long running process and container exits after the execution but in this case I have something that keep containers running.

I see. Can you share the output of the docker-compose --verbose up command?

After I have added stdin_open: true and tty: true to compose file, I can see the container is up and running.

We can close this issue unless there is any other solution available for this.

I'm not sure what causes the discrepancy, although it's likely there would be some slight differences between how Windows containers operate vs how Linux containers operate, so I'll chalk it up to that. If the solution you've outlined is satisfactory for you, I'll go ahead and close.

I experienced this same issue as well. I can run it using docker run just fine but docker-compose up gives exit code 0 for one of my services.
I'm using a macbook and what made it work was EITHER stdin_open: true or tty: true.

My docker-compose.yml:

komuniki-mongo:
  image: mongo
  container_name: "komuniki-mongo"
  volumes:
    - ./temp/mongo_backups:/data/db/mongo_backups
  ports:
    - '27017:27017'

app:
  mem_limit: 300m
  memswap_limit: 1g
  container_name: "komuniki"
  build: .
  volumes:
    - .:/home/nodejs/app
    - ./node_modules:/home/nodejs/app/node_modules
  ports:
    - '7000:7000'
  links:
    - komuniki-mongo:mongo

verbose log.txt

Would be great to know the root cause of this.

FWIW this still occurs on Mac OS X 10.12.6, Docker version 18.04.0-ce-rc2, build f4926a2, docker-compose version 1.20.1, build 5d8c71b

The workaround still works, too.

Suggested solution here does not work, like described from muhfuhcaw

Add -tty: true . Reference :https://docs.docker.com/compose/compose-file/

None of them worked for me (tty or stdin_open).
I am using Mac OS 10.12.6. and I have tried docker-compose version 2 and 3.

@ehongyu
Please try docker-compose.yml with version 3. Be careful with yml syntax.
You can "docker stack deploy" or "docker-compose".
For easy help, You can draw your model and attach some pictures about your docker-compose.yml file

Thanks, @vanquangthanhhao . Actually I found what could be the real cause: my container only has a simple launch script, so once the launch script finished, the container exit with 0. To avoid that, I add a long running command at the end, such as ping localhost, and then the instance stays alive.

capture
I think that you add a running command at the end will increase workload if you run container a long time.

I have the same issue but then found the error.
I was writing some wrong command in Docker file.

So need to investigate the issue you need to comment your commands and check with rebuild. It will show you the issue.

Thanks, @vanquangthanhhao . Actually I found what could be the real cause: my container only has a simple launch script, so once the launch script finished, the container exit with 0. To avoid that, I add a long running command at the end, such as ping localhost, and then the instance stays alive.

This method worked for me . But wanted to ask does this method had a overhead on long term running container.

capture
I think that you add a running command at the end will increase workload if you run container a long time.

It did not work either

When I execute "docker-compose up", I am getting the following error.
image

Someone please give me any suggestion.
Thank you.

@wipitech the npm script is not found. Can you check your Dockerfile to see if you've installed the node properly?

If you already have a service to run on windows container, you can define an entrypoint to your DOCKERFILE and wait for service until it is down. You could be done with following.

Note: Important thing is, if you wanna add code below, you have to change your shell to powershell. Otherwise it won't work.

ENTRYPOINT $nid = (Get-Process <service-name-you-have>).id;\
                     Wait-Process -Id $nid;
Was this page helpful?
0 / 5 - 0 ratings