0

I've the following docker-compose file, and need some help with PHP composer part commented below:

version: '3'
services:
  proxy:
    image: jwilder/nginx-proxy
    container_name: proxy
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - './certs:/etc/nginx/certs'
      - '/var/run/docker.sock:/tmp/docker.sock:ro'
    restart: always
  web:
    image: 'nginx:latest'
    container_name: nginx
    volumes:
      - './volume1:/volume1'
      - './volume2:/volume2'
      - './volume3:/volume3'
      - './site.conf:/etc/nginx/conf.d/site.conf'
    environment:
      - 'VIRTUAL_HOST=host1.local,host2.local,host3.local'
    restart: always
  php:
    build: .
    container_name: php
    volumes:
      - './volume1:/volume1'
      - './volume2:/volume2'
      - './volume3:/volume3'
    restart: always

  # Start How TODO this?
  composer:
    image: 'composer:latest'
    container_name: composer
    command: install
    volumes:
      - './volume1:/app'
      - './volume2:/app'
      - './volume3:/app'
  # End HOW TODO this?

  db:
    image: mariadb
    container_name: mariadb
    ports:
      - '3306:3306'
    environment:
      - MYSQL_ROOT_PASSWORD=toor
    volumes:
      - './db:/var/lib/mysql'
    restart: always
  pma:
    image: phpmyadmin/phpmyadmin
    container_name: pma
    environment:
      - PMA_ARBITRARY=1
      - 'PMA_ABSOLUTE_URI=https://pma.local/'
      - VIRTUAL_HOST=pma.local
    restart: always

I've multiple app that needs to use composer, but I can't overwrite /app folder inside the composer container. Should I write a Dockerfile inside each single app folder? I don't want to specify the full path of PHP app inside the docker-compose, because I can have multiple version of an app (like 1.0, 2.0, ecc.ecc.).

1 Answer 1

1

Instead of putting the Composer configuration in your Docker Compose file, you should probably just run it once for each PHP app before you run the system.

docker run --rm -v $(pwd)/volume1:/app composer:latest install

This will run composer and bind the directory to your host filesystem so that the vendor folder will be available.

Sign up to request clarification or add additional context in comments.

2 Comments

How can I automate this? Should I write that, manually, for each app?
Yeah, I would have a 'build' step that runs composer install on all three apps and then a 'run' step that uses docker-compose to spin up the app. I tend to write shell scripts or NPM scripts to automate those kind of tasks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.