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 ?

  • hbase hadoop DNS static init fails with UnknownHostException in docker while spring bean init if log file exists, but works after init
  • docker private image can not be pulled in centos7
  • Can't push or pull to/from docker registry on localhost
  • Docker Store Vs Docker Hub
  • Compose: running a container that exits
  • Dockerfile with tomcat + mysql + filesystem app
  • Docker container unable to clone from github.com
  • Docker - Cannot forward ports for an interactive shell
  • Can not add new user in docker container with mounted /etc/passwd and /etc/shadow
  • Unable to execute shell script with parameter from Dockerfile
  • Is it good practice to have my sites cert.key and cert.pem in a Nginx Docker container?
  • Get all running Docker containers whose image is derived from a specific image
  • 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.

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.