Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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"
like image 424
Tim Avatar asked May 08 '16 13:05

Tim


People also ask

Can a Docker container have multiple services?

It's ok to have multiple processes, but to get the most benefit out of Docker, avoid one container being responsible for multiple aspects of your overall application. You can connect multiple containers using user-defined networks and shared volumes.

Can I have multiple Docker compose files?

Using Multiple Docker Compose Files Use multiple Docker Compose files when you want to change your app for different environments (e.g., dev, staging, and production) or when you want to run admin tasks against a Compose application.


1 Answers

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
like image 83
JesusTinoco Avatar answered Oct 24 '22 03:10

JesusTinoco