How to create a Docker volume mapped to a server-specific path
Mouting the volume from the host to container
Step1: Create the volume with the custom path
docker volume create --name my_test_volume --opt type=none --opt device=/home/jinna/Jinna_Balu/Test_volume --opt o=bind
Step2 : Mount to the container or swarm service
docker run -d \
--name devtest \
--mount source=my_test_volume,target=/app \
nginx:1.11.8-alpine
We can do both of the above steps with below .yaml files
version: '3'
services:
nginx:
image: nginx:1.11.8-alpine
ports:
- "8081:80"
volumes:
- my_test_volume:/usr/share/app
volumes:
my_test_volume:
driver: local
driver_opts:
o: bind
type: none
device: /home/jinna/Jinna_Balu/Test_volume
RUN the above yml with docker-compose
docker-compose up -d
1 Like