Create docker volume device/host path

Docker recommends creating volumes in the default location. However, designating location will be easy for data transferring. Especially, dockers for internal use will not be exposed to the public, and thus security is not a big issue.

A couple options:

Copy into container

1
docker cp /path/of/the/file <Container_ID>:/path/of/he/container/folder

Not a persistent way, because of no volumes involved

Attach a directory as volume

Create

1
docker volume create --name my_test_volume --opt type=none --opt device=/home/../Test_volume --opt o=bind

Mount

1
2
3
4
docker run -d \
--name container_name \
--mount source=my_test_volume,target=/mount_point \
image_name

The two steps are actually modifying the container yaml file and compose it.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
version: '3'
services:
nginx:
image: image_name
ports:
- "8081:80"
volumes:
- my_test_volume:/mount_point
volumes:
my_test_volume:
driver: local
driver_opts:
o: bind
type: none
device: /home/../Test_volume
1
docker-compose up -d