0
0
Dockerdevops~20 mins

Sharing volumes between containers in Docker - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Volume Sharing Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
💻 Command Output
intermediate
2:00remaining
Output of volume sharing with named volume
What is the output of the following commands when sharing a named volume between two containers?
Docker
docker volume create shared_data

docker run -d --name writer -v shared_data:/data busybox sh -c "echo 'hello' > /data/greeting.txt && sleep 300"

docker run --rm -v shared_data:/data busybox cat /data/greeting.txt
A
Error: volume shared_data not found
B
cat: /data/greeting.txt: No such file or directory
Chello (without newline)
D
hello
Attempts:
2 left
💡 Hint
Think about how named volumes persist data and are shared between containers.
Configuration
intermediate
2:00remaining
Correct docker-compose volume sharing syntax
Which docker-compose.yml snippet correctly shares a volume named 'shared_data' between two services 'app1' and 'app2'?
A
version: '3'
services:
  app1:
    image: busybox
    volumes:
      - ./shared_data:/data
  app2:
    image: busybox
    volumes:
      - ./shared_data:/data
B
version: '3'
services:
  app1:
    image: busybox
    volumes:
      - /data/shared_data:/data
  app2:
    image: busybox
    volumes:
      - /data/shared_data:/data
C
version: '3'
services:
  app1:
    image: busybox
    volumes:
      - shared_data:/data
  app2:
    image: busybox
    volumes:
      - shared_data:/data
volumes:
  shared_data: {}
D
version: '3'
services:
  app1:
    image: busybox
    volumes:
      - shared_data
  app2:
    image: busybox
    volumes:
      - shared_data
volumes:
  shared_data: {}
Attempts:
2 left
💡 Hint
Named volumes are declared under 'volumes' and referenced with 'volume_name:container_path'.
Troubleshoot
advanced
2:00remaining
Why data is missing when sharing host directory volume
You mounted a host directory as a volume in two containers to share data. Container A writes a file, but Container B cannot see it. What is the most likely cause?
AThe host directory was mounted as read-only in Container B
BThe containers are on different Docker networks
CThe volume was declared as a named volume instead of a bind mount
DContainer A did not have write permissions on the host directory
Attempts:
2 left
💡 Hint
Check the mount options for the volume in Container B.
🔀 Workflow
advanced
2:00remaining
Steps to share data between containers using volumes
What is the correct order of steps to share data between two running containers using a named volume?
A2,1,3,4
B1,2,3,4
C1,3,2,4
D2,3,1,4
Attempts:
2 left
💡 Hint
Think about creating the volume before using it in containers.
Best Practice
expert
3:00remaining
Best practice for sharing sensitive data between containers
Which is the best practice for securely sharing sensitive configuration files between multiple containers?
AUse Docker secrets or a dedicated secrets management tool
BUse a Docker named volume with encrypted filesystem on the host
CUse environment variables to pass sensitive data to each container
DMount a host directory with sensitive files as a bind mount in all containers
Attempts:
2 left
💡 Hint
Consider security and access control for sensitive data.