Skip to content

Commit bac311b

Browse files
authored
Create README.md
1 parent 5ef4166 commit bac311b

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed

cheatsheet/README.md

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
2+
#stop and Remove ALL containers
3+
docker stop $(docker ps -aq); docker rm $(docker ps -aq)
4+
5+
#stop ALL containers
6+
docker stop $(docker ps -a -q)
7+
8+
# remove ALL containers
9+
docker rm -f $(docker ps -a -q)
10+
11+
12+
For Containers :
13+
docker stop $(docker ps -qa)
14+
docker rm $(docker ps -qa)
15+
16+
17+
For Images :
18+
docker rmi $(docker images -qa)
19+
docker images
20+
docker rmi -f b00ea124ed62 529165268aa2 0c45f7936948
21+
docker images
22+
23+
24+
Volume Example usage:
25+
26+
docker run -v c:\ContainerData:c:\data:RO for read-only access
27+
docker run -v c:\ContainerData:c:\data:RW for read-write access
28+
docker run -v c:\ContainerData:c:\data for read-write access (default)
29+
30+
31+
docker run -itd -p 8030:80 -m 1GB --name nginx1 -v c:/html:/usr/share/nginx/html nginx
32+
33+
docker run -itd -p 8040:80 -m 1GB --name nginx2 -v c:/html:/usr/share/nginx/html:ro nginx:v2
34+
35+
36+
37+
Docker run :
38+
39+
--privileged
40+
$ docker run -t -i --rm ubuntu bash
41+
root@bc338942ef20:/# mount -t tmpfs none /mnt
42+
mount: permission denied
43+
44+
$ docker run -t -i --privileged ubuntu bash
45+
root@50e3f57e16e6:/# mount -t tmpfs none /mnt
46+
root@50e3f57e16e6:/# df -h
47+
Filesystem Size Used Avail Use% Mounted on
48+
none 1.9G 0 1.9G 0% /mnt
49+
50+
51+
-w
52+
$ docker run -w /path/to/dir/ -i -t ubuntu pwd
53+
The -w lets the command being executed inside directory given, here /path/to/dir/.
54+
Note : If the path does not exist it is created inside the container.
55+
56+
docker run -itd -p 8050:80 -m 1GB --name nginx3 -w //usr//share//nginx//html -v c:/html:/usr/share/nginx/html nginx
57+
58+
59+
60+
-e, --env, --env-file
61+
$ docker run -e MYVAR1 --env MYVAR2=foo --env-file ./env.list ubuntu bash
62+
63+
$ docker run --env VAR1=value1 --env VAR2=value2 ubuntu env | grep VAR
64+
VAR1=value1
65+
VAR2=value2
66+
67+
68+
Limiting Memory
69+
$ docker run -d -p 8081:80 --memory=20m --memory-swap=20m nginx
70+
$ docker container run -d --memory-reservation=250m --name mymem1 alpine:3.8 sleep 3600
71+
72+
73+
Limiting CPU
74+
--cpus
75+
Docker 1.13 and higher:
76+
$ docker run -it --cpus=".5" ubuntu /bin/bash
77+
78+
Docker 1.12 and lower:
79+
$ docker run -it --cpu-period=100000 --cpu-quota=50000 ubuntu /bin/bash
80+
$ docker run -it --cpus-shares="512" ubuntu /bin/bash
81+
82+
83+
docker stats :
84+
85+
$ docker stop $(docker ps -aq); docker rm $(docker ps -aq)
86+
$ docker run -itd -p 8030:80 --name nginx7 -v c:/html:/usr/share/nginx/html:ro nginx:v2
87+
$ docker stats
88+
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
89+
779eb8148aa7 nginx7 0.00% 1.914MiB / 8.75GiB 0.02% 906B / 0B 0B / 4.1kB 2
90+
91+
92+
93+
Create and start a container
94+
$ docker create -t -i fedora bash
95+
6d8af538ec541dd581ebc2a24153a28329acb5268abe5ef868c1f1a261221752
96+
97+
$ docker start -a -i 6d8af538ec5
98+
bash-4.2#
99+
100+
101+
Copy :
102+
103+
Copy a file from host to container:
104+
docker cp Dockerfile 779eb8148aa7:/tmp/Dockerfile
105+
docker exec -it 779eb8148aa7 //bin/bash
106+
docker cp Dockerfile 779eb8148aa7:/tmp/Dockerfile123
107+
docker exec -it 779eb8148aa7 //bin/bash
108+
109+
Copy a file from Docker container to host:
110+
docker cp 779eb8148aa7:/tmp/Dockerfile123 Dockerfile_Delete
111+
112+
113+
Copy a Folder from host to container:
114+
docker cp /home/captain/my_dir ubu_container:/home
115+
docker cp ubu_container:/home/my_dir /home/captain
116+
117+
118+
Logs :
119+
$ docker logs 779eb8148aa7 --follow
120+
121+
122+
123+

0 commit comments

Comments
 (0)