Volumes Flashcards
(29 cards)
What are Volumes?
The way the filesystem of a docker container is stored and used
Each volume act like a separate ___
Drive
What are the types of volumes?
- Anonymous volume
- Named volume
- Bind Volume
- Tmpf Volume
By default, Docker uses what kind of volume?
Anonymous volume
What are the 2 ways we can create a new volume?
- docker-compose.yml file
2. Docker Desktop app
How do we create a volume in the docker-compose.yml file?
Need:
- Volumes section
- Declare name of new volume
How do we create a volume in Docker Desktop app?
- Click ‘New Volume’ button
2. Enter volume name
Add the volume ‘my_volume’ to this docker-compose.yml file located at var/www/log
webserver: build: ./app1 ports: - "80" volumes: - my_volume:/var/www/log
Can the same volume be mounted on multiple containers?
Yes
A file can only be written to ____ to avoid lockup/access issues
one container at a time
A file can only be written to ____ to avoid lockup/access issues
one container at a time
What are the 2 types of syntax you can use when declaring a volume?
- Short syntax
2. Long syntax
What is short syntax?
Give an example
volumes:
- new_volume:/var/www/log
What is long syntax?
Give an example
volumes:
- type: volume source: my_new_volume target: /var/www/log
What is long syntax?
Give an example
volumes:
- type: volume source: my_new_volume target: /var/www/log
What can you use for the source in short syntax?
- Name
- Path
What can you use for the source in long syntax?
- Name
What can you use for the source in long syntax?
- Name
What is are Bind Volumes?
Binds a local folder on the host to the container
What is a pro to using Bind Volumes?
Allows easy access on the host
What is a con to using Bind Volumes?
Risky when deploying between hosts as permissions may not work
How can you make a volume read-only?
Why might you do this?
volumes: - type: volume source: my_new_volume target: /var/www/log read_only: true
You can config files that containers need by shouldn’t modify
How can you make a volume nocopy?
Why might you do this?
volumes: - type: volume source: my_new_volume target: /var/www/log volume: nocopy: true
Good if you have a shared volume but you want it to occupy a space that would have had others files in it already
Which type of volume doesn’t use the source command?
Tmpf Volumes