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 ?

  • Python script to add data to postgres docker container runs multiple times
  • Connection refused when trying to access SOLR instance running in boot2docker on windows
  • Why doesn't docker accept non-local MAC addresses?
  • nginx ipv6 communication with docker containers
  • Seeding a MySQL DB for a Dockerized Django App
  • 404 error when Accessing from local host : NGINX uWSGI
  • How to access a remote django app that's running on docker
  • Running the official consul docker image
  • Mesos/Marathon on EC2 agents hostnames not accessible
  • Docker container can't resolve DNS to reach another AWS Ec2 Machine
  • Nginx doesn't get host from embedded DNS in docker 1.10.1
  • Why can't the container display the content of mounting directory of host?
  • 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.