Volumes Flashcards
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
Why might you use tmpf?
If youre working with sensitive data
You want to limit size
Declare a tmpf volume with max size of 100B
volumes:
- type: tmpfs target: /var/www/log tmpfs: size: 100B
What is the peculiarity of using tmpfs on the WSL (Windows Subsystem for Linux)?
- Doesnt support tmpfs
- Writes to a file instead of memory, which isn’t cleared when the container is killed
- Doesnt respect the size command
What is the peculiarity of using tmpfs on the WSL (Windows Subsystem for Linux)?
- Doesnt support tmpfs
- Writes to a file instead of memory, which isn’t cleared when the container is killed
- Doesnt respect the size command
What type of volume would never have files be copied from the underlying container into the volume during setup? Why?
Bound Volumes
Security issue: Files could be copied anywhere on the host, meaning file can end up somewhere it shouldn’t