Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

docker-compose up is starting the container and immediately stopping them

I am trying to build services using docker-compose but containers started using docker-compose is stopping immediately as compose script is over. But when i am creating container using docker run for the same service image it is working.

Here is my compose script:

version: '2.1'

networks:
 composetestnetwork:
  driver: bridge
   ipam:
    driver: default
    config:
     - subnet: 172.19.0.0/16
       gateway: 172.19.0.1

services:
 composetestdb:
  build:
   context: .
   dockerfile: Dockerfile-testdb
  cap_add:
   - ALL
  container_name: my-db-compose-container
  labels:
   db.description: "This is a test db"
  volumes:
   - c:/Users:/data
  networks:
   composetestnetwork:
    ipv4_address: 172.19.0.5
  ports:
   - "3306:3306"
  command: 'bash'

What can be done to fix this.

like image 529
kunal kashyap Avatar asked Mar 04 '17 07:03

kunal kashyap


1 Answers

If you use bash as the command, but without a terminal, it will exit immediately. This is because when bash starts up, if there is no terminal attached, and it has no script or other command to execute, it has nothing to do, so it exits (by design).

You can either use a different command, or attach a terminal with tty: true as part of the definition of this service.

services:
  composetestdb:
    tty: true
    ...
like image 107
Dan Lowe Avatar answered Oct 22 '22 22:10

Dan Lowe