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.

  • How to exit a Docker Remote API Exec Stream?
  • Passing parameter in docker build command with fish
  • Is it possible to run mutliple docker machines within one virtual machine (virtualbox)?
  • Script to check mosquitto is healthy
  • running java applications in docker with jboss or tomcat server
  • How to create a volume with given size in flocker?
  • 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!

  • Pull private docker images from Google Container Registry w/o gcloud
  • Docker Rails app fails to be served - curl: (56) Recv failure: Connection reset by peer
  • Docker-compose: close ports after SIGTERM
  • I started a docker container with --rm Is there an easy way to keep it, without redoing everything?
  • Deploying Golang web app static files with Docker container
  • Enable webcam in docker application and access thru AWS ECS
  • 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.