Multiple Websites and PHP Versions with Docker-Compose

At the moment I’m building my own dev environment because I want to get rid of MAMP.

I created a docker-compose file with a nginx proxy and it’s basically working. My problem is, that several old php projects require different php versions.

  • Mixing cpu-shares and cpuset-cpus in Docker
  • Docker: where should I put container configuration and war file
  • Mounted docker volumes corrupting files
  • how to limit number of streams when pulling docker image
  • angular app with docker - production & development
  • How can i mount /dev/shm in a docker container
  • Here is how far I already got with my compose file:

    version: '2'
    services:
      nginx-proxy:
        image: jwilder/nginx-proxy
        container_name: nginx-proxy
        ports:
          - "80:80"
        volumes:
          - /var/run/docker.sock:/tmp/docker.sock:ro
    
      project1:
        build: ./config/5.3.29/nginx/
        container_name: project1
        volumes:
            - ./project1/:/var/www/html
        links:
            - php-5.3.29:php        
        environment:
          - "VIRTUAL_HOST=project1.org"
        expose:
          - "8080"
    
      project2:
        build: ./config/5.6/nginx/
        container_name: project2
        volumes:
            - ./project2/:/var/www/html
        links:
            - php-5.6:php       
        environment:
          - "VIRTUAL_HOST=project2.de"
        expose:
          - "8081"
    
      php-5.3.29:
        build: ./config/5.3.29/php/
        container_name: php-5.3.29
        ports:
            - 9000:9000
    
      php-5.6:
        build: ./config/5.6/php/
        container_name: php-5.6
        ports:
            - 9001:9000
    

    As you can see, I have two projects. The PHP containers require to volume from the the same path as the project does. Is there a way to generate the path dynamically? Project 3 will also use php 5.6.

    Or am I using the wrong way to go in general? In the end there will be around 10 Magento online shops.

    Thank you for your help!

  • Docker - Feed data from read-only directory on host into container
  • Generic Docker Image and Dockerfile for SpringBoot Apps using Gradle
  • Setting up jupyterhub docker using one of the jupyter stacks
  • Connecting to Dockerized MySQL from remote client
  • Microservice registration with Eureka replicas in docker swarm cluster
  • Docker network with AWS VPC
  • 2 Solutions collect form web for “Multiple Websites and PHP Versions with Docker-Compose”

    You can reference directories above the compose file like ../sites:/var/www/html or similar. Not sure when you say “dynamically” if you need additional logic to generate the paths.

    In general it seems like your naming is a bit too specific, which might be fine for an initial workstation, but as things start to change, it’s going to be harder to maintain.

    Thank you for your answer!

    Today I was able to solve my problem with this docker-compose file:

    version: '2'
    services:
      nginx:
        build: ./config/nginx/
        container_name: nginx
        volumes_from:
            - www_data
        links:
            - php-5.3.29
            - php-5.5
        ports:
          - 80:80
    
      php-5.3.29:
        build: ./config/5.3.29/
        container_name: php-5.3.29
        volumes_from:
            - www_data
    
      php-5.5:
        build: ./config/5.5/
        container_name: php-5.5
        volumes_from:
            - www_data
    
      php-5.6:
        build: ./config/5.6/
        container_name: php-5.6
        volumes_from:
            - www_data
    
      www_data:
        image: tianon/true
        volumes:
          - .:/var/www/html
    

    I removed the proxy and used the nginx config to handle the different websites. Then I was able to include the different php versions like this:

    fastcgi_pass php-5.5:9000;
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.