Docker Compose run a command
I would like to run a command with docker compose, it is not working, the container starts and disappear without any errors
web: image: nginx:latest ports: - "8888:80" volumes: - ./dir:/dir command: bash -c "chown -R www-data:www-data /dir" links: - php
I think that the command is being executed but the container stops then, should I add something else ?
One Solution collect form web for “Docker Compose run a command”
What I usually do and recommend is to use commands only inside Dockerfile (
RUN chown -R www-data:www-data /dir). If you need to run anything at “boot time” (for example keep container running), you can do this at your docker-compose.yml:
web: image: nginx:latest ports: - "8888:80" volumes: - ./dir:/dir entrypoint: /root/start_services.sh links: - php
and inside start_services.sh, you need to run
tail -f /var/log/syslog to keep the container runnning.
start_services.sh file is copyied into /root dir inside container.