Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

476
Visualizações
docker-compose volumes_from equivalent with version 3

I'm trying to create an Nginx/PHP FPM setup with docker compose and am having issues with the version 3 volumes syntax/changes.

My Dockerfile:

FROM php:7-fpm
VOLUME /var/www/html

My docker-compose.yml:

version: "3"
services:
  php:
    build: .
    volumes:
      - ./html:/var/www/html
  web:
    image: nginx
    links:
      - php
    ports:
      - "8888:80"
    volumes:
      - php:/var/www/html
      - ./default.conf:/etc/nginx/conf.d/default.conf
volumes:
  php:

When I add an index.php file into ./html, I can view that by going to http://localhost:8888, but any static files (like CSS) return a 404 because Nginx cannot find those in its container (/var/www/html is empty on the nginx container). With version 3 docker compose files do not have volumes_from anymore, which is basically what I'm trying to replicate.

How can I get this to work with version 3?

over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

For using "Named volumes" for sharing files between containers you need to define

1) volumes: section on the top level of yml file and define volume name

volumes:
  php:

2) define volume section on first container like you did (Where share will mount)

web:
    volumes:
      - php:/var/www/html #<container_name>:<mount_point>

3) define volume section on second container (Share will mount from)

php:
  volumes:
    - php:/var/www/html

4) (optionally) If you need to store volume data on the host machine you can use local-persist docker plugin. You can specify docker volume driver and path where you data will be stored.

volumes:
  php:
    driver: local-persist
    driver_opts:
      mountpoint: /path/on/host/machine/

In your case you forgot define volume name for php container. Just replace

  php:
    build: .
    volumes:
      - ./html:/var/www/html

to

  php:
    build: .
    volumes:
      - php:/var/www/html

and use Local Persist Docker Plugin

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda