-
Notifications
You must be signed in to change notification settings - Fork 114
/
Copy pathdocker_volumes
80 lines (52 loc) · 1.94 KB
/
docker_volumes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# To Check storage driver in your system
$ docker info |grep Storage
Storage Driver: overlay2
# To check docker’s local storage area
$ docker info |grep "Docker Root Dir"
Docker Root Dir: /var/lib/docker
# To Change the storage driver
sudo systemctl stop docker
$ sudo cat daemon.json
{
"storage-driver": "devicemapper"
}
Start the docker daemon
sudo systemctl start docker
NOTE: Changing storage driver wiped out all the image
# To create a volume
$ docker volume create mytestvol
# To verify it
$ docker volume ls
# Run a container using this Volume
$ docker container run -dt --name mytestvol -v mytestvol:/etc centos bash
# Check the location of Volume in Host system
$ docker volume inspect mytestvol |grep Mountpoint
# Creating data container
docker create -v myvolshare --name myvolshare centos bash
# Share it with other container
docker container run -dt --volumes-from myvolshare --name mytest centos bash
# To delete a volume
$ docker volume rm mytestvol
# Bind mount the volume
docker run -dt --name mybindmount -v ~/index:/usr/share/nginx/html -p 8080:80 nginx
# Different way to specify bind mount
docker container run -dt --name mybindmount01 --mount type=bind,source=/home/cloud_user/index,target=/usr/share/nginx/html -p 8081:80 nginx
# Read only bind mount
docker container run -dt --name mybindmount03 --mount type=bind,source=/home/cloud_user/index,target=/usr/share/nginx/html,readonly -p 8082:80 nginx
# Remove all unused local volumes
$ docker volume prune
# Create the volume using Dockerfile
FROM busybox
RUN mkdir /mytestvol
RUN echo "testing volume" >> /mytestvol/test.txt
VOLUME /mytestvol
# Build the image
docker build -t mytestvol .
# Run the container using this Volume
docker container run -dt --name mytestvol 95aed0e870d1 sh
# Verify the volume
docker volume ls
# Assign a name to your volume
docker container run -dt --name mytestvol01 -v testvol:/mytestvol 95aed0e870d1 sh
# Verify the volume
docker volume ls