Status Exited (0) after a docker-compose up command

3

I'm starting to work with Docker now, I understand the concepts of images and containers but I have a problem to run the command:

$ docker-compose up

I created a Dockerfile in the root of my project to create a container with the main components that 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 made the composition of Dockerfile with docker-compose.yml , creating 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 run the command:

$ docker-compose up

Apparently everything is 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 run the command:

$ docker ps -a

The Conatiner App has status e

Exited (0) 6 seconds ago  

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

    
asked by anonymous 18.06.2018 / 16:07

2 answers

0

Containers use a concept that you have to execute what you ask for and then die, or if the container is already made to die.

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

In your case try to pass in the image or in the docker-compose what should be executed

Dockerfile

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

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

try adapting to your project

read this may help you

    
21.12.2018 / 02:45
-1

Have you tried adding the tty tag? Here's an example:

version: '3'

services:

  app:

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

It worked for me when I was using a nginx server and mysql db

    
12.07.2018 / 20:44