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?– Bruno César
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.
– Matheus Freitas
Right. Include at the end of
Dockerfile
this:ENTRYPOINT ["mvn", "spring-boot:run"]
. In this case you don’t need oneCMD
, 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 César
Bruno managed to make the bank run, thank you very much for the tip.
– Matheus Freitas
Show, then put your solution as an answer, it can be useful for other people.
– Bruno César
What you see on the console when you run? Docker-Compose up
– Marconi