Docker compose and volumes

Expected behavior

I want to mount a volume like that in a docker-compose.yml:
web:
volumes:

  • “www:/var/www/html”

I want to see my files that are in “www” in the container

Actual behavior

When launched, no files are in the container. But, this works:
web:
volumes:

  • “.:/var/www/html”

So I can’t mount several volumes.

Information

  • the output of:
    • pinata diagnose -u on OSX
    • DockerDebugInfo.ps1 using Powershell on Windows
  • a reproducible case if this is a bug, Dockerfiles FTW
  • page URL if this is a docs issue or the name of a man page
  • host distribution and version ( OSX 10.10.x, OSX 10.11.x, Windows, etc )

Steps to reproduce the behavior

  1. create a docker-compose.yml
  2. docker-compose.exe up
1 Like

Hi,

The behavior you described is normal and expected. In a docker-compose file, relative paths (such as your “www” folder) should always begin with . or …
Reference: https://docs.docker.com/compose/compose-file/#volumes-volume-driver

You should use:
web:
volumes:
- “./www:/var/www/html”

Your ‘- “www:/var/www/html”’ creates a named volume (named “www”). Do a ‘docker volumes ls’ and you should see it.

You’re right. I forgot it when I created the post.

./www does not work