More on the Docker Compose File
Learn more properties that you can add in the docker-compose.yml file.
Attach persistent Docker volumes
Mount a Docker volume (created on first use) or bind a host directory:
mycontainer:
volumes:
#Docker volume
- type: volume
source: rootfiles
target: /var/www/html
#bind host directory
- type: bind
source: ./myfiles
target: /var/www/html/myfiles
A shorter syntax can also be used to define <source>:<destination>
. The <source>
is presumed to be Docker volume unless it starts with .
or ..
relative file paths.
mycontainer:
#idential to above
volumes:
- rootfiles:/var/www/html
- ./myfiles:/var/www/html/myfiles
Docker volumes (and optional configurations) must be referenced after the services:
definition at the bottom of docker-compose.yml
: ...