Status Exited (0) after a Docker-Compose up command

Asked

Viewed 940 times

4

I’m starting to work with Docker now, I understand the concepts of images and containers but I’m having a problem running the command:

$ docker-compose up

I created a Dockerfile at the root of my project to create a container with the main components I need for my application to run:

FROM ubuntu:xenial-20180525
MAINTAINER Matheus Freitas <[email protected]>
RUN mkdir /home/sog-imn/
ADD . /home/sog-imn
WORKDIR /home/sog-imn
RUN apt-get update
RUN apt-get -y upgrade
RUN apt-get install -y erlang
RUN apt-get install -y rabbitmq-server
RUN apt-get install -y default-jdk
RUN apt-get install -y maven
RUN bash nodesource_setup.sh && apt-get install -y nodejs
RUN apt-get install -y build-essential
RUN npm install bower -g
RUN npm install gulp-cli -g
RUN npm install gulp -D
RUN npm install less -g
RUN npm install browser-sync -g
EXPOSE 8081

I wrote the Dockerfile with the docker-compose.yml, creating the Networks:

version: '3'
services:
  app:
    build: .
    ports:
      - "8081:80"
    networks:
      - backend
  db:
    image: postgres:9.6
    volumes:
      - db-data:/var/lib/postgresql/data
    networks:
      - postegres
networks:
  backend:
  postegres:
volumes:
  db-data:

When I turn the remote:

$ docker-compose up

Apparently it’s all right in the console log...

MacBook-Pro-de-Matheus:sog-imn matheusfreitas$ docker-compose up
Creating sog-imn_app_1 ... done
Creating sog-imn_db_1  ... done
Attaching to sog-imn_app_1, sog-imn_db_1
sog-imn_app_1 exited with code 0
db_1   | LOG:  database system was shut down at 2018-06-18 13:38:31 UTC
db_1   | LOG:  MultiXact member wraparound protections are now enabled
db_1   | LOG:  autovacuum launcher started
db_1   | LOG:  database system is ready to accept connections

When I turn the remote:

$ docker ps -a

The Conatiner App is with and status

Exited (0) 6 seconds ago  

I do not understand why this, I would like some more information about the possible problems I may be causing and if possible tips on how to solve these problems.

  • Your container is not running anything, so once created it will be stopped anyway, a Docker container finishes running as soon as your main process ends. What would be the ENTRYPOINT\CMD to run your application?

  • Hello Bruno, my application runs the command mvn spring-boot:run <- I think this would be my CMD now ENTRYPOINT I’m not sure but I think it would be the directory in which I run the command mvn spring-boot:run, correct me if I’m wrong.

  • 1

    Right. Include at the end of Dockerfile this: ENTRYPOINT ["mvn", "spring-boot:run"]. In this case you don’t need one CMD, only that you want to pass some parameter and such. Other points: you can use the image of Maven, besides using rabbitmq in another container. I don’t know what’s in this shell script of yours, or how your application is, but you’ll need to tweak your image to run two services in the container. See in this reply how to run more than one service: https://answall.com/questions/240037/241084#241084

  • Bruno managed to make the bank run, thank you very much for the tip.

  • Show, then put your solution as an answer, it can be useful for other people.

  • What you see on the console when you run? Docker-Compose up

Show 1 more comment

2 answers

2

Containers use a concept that you have to execute what you ask for and then die, i.e., container is made to die.

What’s happening is that the container is performing all the tasks and then dies, you need to start an application that will leave it alive (or standing), when you spin the docker exec my_image /bin/bash you are starting the terminal process that keeps it alive.

In your case try to pass the image or Docker-Compose what should be executed.

Dockerfile

CMD [ "python3" , "app.py" ]

It is equivalent to the terminal that will execute a script: $ python3 app.py

Try to adapt to your project.

Read this may help you

  • Living and learning, cool did not know it :) Excellent explanation.

-1

Have you tried adding the tty tag? Below is an example:

version: '3'

services:

  app:

    build: .
    ports:
      - "8081:80"
    networks:
      - backend
  tty: true

Worked for me when using a Nginx and mysql db server

Browser other questions tagged

You are not signed in. Login or sign up in order to post.