0

Im building a basic centos image with only some packages but Im forgotting something because finish well but not maintain the container. What Im doing bad?

docker-compose:

version: '3'
services:
  config_server:
    build: ../common/docker/ansible/.
    stdin_open: true
    volumes:
      - ../../api:/var/www/api
      - ../../server:/var/www/server
      - ../server/provision/server:/tmp/ansible
    working_dir: /tmp/ansible
    networks:
      net:
        ipv4_address: 172.28.0.10
    command: ansible-playbook playbook.yml

networks:
  net:
    driver: bridge
    ipam:
      driver: default
      config:
        - subnet: 172.28.0.0/24

Dockerfile:

FROM centos:7
RUN yum makecache && yum install -y epel-release wget
RUN yum install -y ansible

I would like to check If all tasks was well, and using:

docker logs 

I see logs from ansible script finishing well. But I don't know why not maintains container with Exited (0) error

command used is

docker-compose up -d --build 

Suggestions?

deconya
  • 135
  • 2
  • 8
  • It exited because it finished running. There was nothing left to do. – Michael Hampton Aug 19 '20 at 15:50
  • usually when finish with -d it maintains the container up, but which option I need to use to not finish? – deconya Aug 19 '20 at 15:51
  • In order for the container to not exit, it must be running some process! – Michael Hampton Aug 19 '20 at 15:52
  • so If I only would like to control logs of activity, I need to add some extra service to maintain container up, If no I need to use docker run to check state. Not exist any option to maintain container without services? – deconya Aug 19 '20 at 16:03
  • If you just want to preserve logs, you can have them [logged somewhere more persistent](https://serverfault.com/q/1024362/126632), such as to the systemd journal, or an external logging service. – Michael Hampton Aug 19 '20 at 16:06
  • Is a very good option! Thks! https://docs.docker.com/config/containers/logging/configure/#supported-logging-drivers – deconya Aug 19 '20 at 16:09

1 Answers1

0

How @Michael Hampton says, I found a solution inside stackoverflow

https://stackoverflow.com/questions/38546755/docker-compose-keep-container-running/45450456

Basically we need to include command in docker-compose

command: tail -f /dev/null
deconya
  • 135
  • 2
  • 8