0

using yaml inheritance Im trying to share the env variable between different container. It works but the container dies after creating it.

How can I have the container running after its being created.

I use 'docker-compose up -d' to bring up these containers.

version: '3'

services:
  worker: &default      
    image: 127.0.0.1:5000/stackdemo
    env_file:
      - .env
    # entrypoint: ["/tini", "--", "/common-bash"]
  web:
    <<: *default
    image: 127.0.0.1:5000/stackdemo
    build: .
    ports:
      - "8000:8000"
    entrypoint: ["/tini", "--", "/common-bash"]

Also, here is my docker file -

FROM python:3.4-alpine
ADD . /code
WORKDIR /code

ENV TINI_VERSION v0.16.1
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /tini
RUN chmod +x /tini

RUN pip install -r requirements.txt
CMD ["python", "app.py"]

Here is the contents of my common-bash file:

set -e
set USERNAME "test"
exec "$@"
user1050619
  • 19,822
  • 85
  • 237
  • 413

1 Answers1

0

I think your problem is that your running application ( python app.py ) runs as foreground process and just ends the execution a few seconds later after container is up. Docker shuts down those container when foreground process ran by CMD or ENTRYPOINT is stopped. There is a few way you can avoid it. Why docker container exits immediately

wonhee
  • 1,581
  • 1
  • 14
  • 24