[docker] Docker-Compose with multiple services

THIS IS A SAMPLE QUESTION! NEVER DO IT IN PRODUCTION. RUN NGINX / PHP / OTHER SERVICES IN SEPARATE CONTAINERS!

When I start docker-compose up the Ubuntu container exits with ubuntu exited with code 0.

When I run docker run -d -ti -p 80:80 -v ~/sph/laravel52:/www/laravel ubuntu, all works fine.

How can I replicate this behavior using Docker Compose?

This is my Dockerfile:

# Version: 0.0.1
FROM ubuntu:15.04



ENV DEBIAN_FRONTEND noninteractive

#INSTALL ALL
RUN apt-get update && apt-get install -y  \
       nano \
       php5-fpm \
       php5-mysql \
       nginx



#NGINX CONF
ADD nginx/sites-available/laravel.conf /etc/nginx/sites-available/
RUN rm /etc/nginx/sites-available/default
RUN mv /etc/nginx/sites-available/laravel.conf /etc/nginx/sites-available/default

VOLUME /www


ENTRYPOINT nginx && service php5-fpm start && /bin/bash

CMD ["true"]


EXPOSE 80

And docker-compose.yml:

version: '2'
services:
  ubuntu:
        build: .
        container_name: ubuntu
        volumes:
            - ~/sph/laravel52:/www/laravel
        ports:
          - "80:80"

This question is related to docker docker-compose

The answer is


The thing is that you are using the option -t when running your container.

Could you check if enabling the tty option (see reference) in your docker-compose.yml file the container keeps running?

version: '2'
services:
  ubuntu:
        build: .
        container_name: ubuntu
        volumes:
            - ~/sph/laravel52:/www/laravel
        ports:
          - "80:80"
        tty: true

Examples related to docker

standard_init_linux.go:190: exec user process caused "no such file or directory" - Docker What is the point of WORKDIR on Dockerfile? E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation How do I add a user when I'm using Alpine as a base image? docker: Error response from daemon: Get https://registry-1.docker.io/v2/: Service Unavailable. IN DOCKER , MAC How to fix docker: Got permission denied issue pull access denied repository does not exist or may require docker login Docker error: invalid reference format: repository name must be lowercase Docker: "no matching manifest for windows/amd64 in the manifest list entries" OCI runtime exec failed: exec failed: (...) executable file not found in $PATH": unknown

Examples related to docker-compose

E: gnupg, gnupg2 and gnupg1 do not seem to be installed, but one of them is required for this operation How to upgrade docker-compose to latest version How to fix docker: Got permission denied issue Docker error: invalid reference format: repository name must be lowercase Is it safe to clean docker/overlay2/ Docker: How to delete all local Docker images Docker "ERROR: could not find an available, non-overlapping IPv4 address pool among the defaults to assign to the network" How to run docker-compose up -d at system start up? How to create a DB for MongoDB container on start up? How to use local docker images with Minikube?