Unable to automate last part of a tree-step Apache server setup with
docker-compose up. Steps are:
- Build the image (includes Apache configs) and start Apache in
- Mount two directories (bind mounts) with images for the web app to serve [✓]
/bin/bashentrypoint to run script that reads mounted dirs and creates file for the web app [ ]
The container exits with code 0 right after setup is completed!
Linux 4.15.0-33-generic #36-Ubuntu x86_64
Docker 18.06.1-ce, build e68fc7a
docker-compose 1.22.0, build f46880fe
Steps to reproduce
Step 1 of the setup can be configured within the Dockerfile and
CMD for starting Apache.
FROM ubuntu:16.04 RUN apt-get update -y RUN DEBIAN_FRONTEND=noninteractive apt-get -y -o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold" upgrade RUN apt-get install -y apache2 libapache2-mod-perl2 libcgi-session-perl libapache2-mod-php make php python ... EXPOSE 80 CMD ["/usr/sbin/apache2ctl", "-D", "FOREGROUND"]
However, the remaining steps can only be performed when spinning a container(?). I was hoping to simply run
docker-compose up and let the compose file mount the dirs and
command execute the script.
version: '3' services: server: build: . volumes: - ./volume/Images/:/var/www/html/LabelMeAnnotationTool/Images/:rw - ./volume/Annotations/:/var/www/html/LabelMeAnnotationTool/Annotations/:rw ports: - 80:80 command: ["/bin/bash","-c","python","populate-dirlist.py"]
My guess is the ‘exit code 0’ is due to the fact that
command is overwriting the entrypoint of the container and since
/bin/bash is “non-blocking”, it exists right away.
My question is then: How can I make sure that python script runs after the dirs are mounted, while keeping apache running in foreground?