More on the Docker Compose File
Explore detailed Docker Compose file configurations covering volume mounting, port exposure, custom DNS servers, container linking, restart policies, healthchecks, and logging options. Understand how to enhance container control and service interaction in your Docker setups for web development projects.
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 ...