-
Notifications
You must be signed in to change notification settings - Fork 2
/
Docker_cheatsheet.txt
70 lines (61 loc) · 2.71 KB
/
Docker_cheatsheet.txt
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
## List Docker CLI commands
docker
docker container --help
## Display Docker version and info
docker --version
docker version
docker info
## Execute Docker image
docker run hello-world
## List Docker images
docker image ls (hides intermediate images)
docker image ls -a (show all)
## List Docker containers (running, all, all in quiet mode)
docker container ls (== docker ps)
docker container ls --all
docker container ls -aq
docker pull <OPTIONS> <NAME><:TAG|@DIGEST> # get new image from docker hub
docker build -t friendlyhello . # Create image using this directory's Dockerfile
docker run -p 4000:80 friendlyhello # Run "friendlyhello" mapping port 4000 to 80
docker run -d -p 4000:80 friendlyhello # Same thing, but in detached mode
docker container stop <hash> # Gracefully stop the specified container
docker container kill <hash> # Force shutdown of the specified container
docker container rm <hash> # Remove specified container from this machine
docker container rm $(docker container ls -a -q) # Remove all containers
docker container prune # Remove all stopped containers
docker image rm <image id> # Remove specified image from this machine
docker image rm $(docker image ls -a -q) # Remove all images from this machine
docker image prune # Remove unused images
docker login # Log in this CLI session using your Docker credentials
docker tag <image> username/repository:tag # Tag <image> for upload to registry
docker push <options> username/repository:tag # Upload tagged image to registry
docker run username/repository:tag # Run image from a registry
From attached container terminal:
ctrl+P+Q: detach
docker attach <container>: re-attach terminal to running container
Migrate docker root directory to different drive
1. Change drive mounting config
remove "nosuid"
2. Stop docker deamon
sudo service docker stop
3. Create or edit /etc/docker/daemon.json and add
{
"data-root": "/path/to/your/new/docker/root"
}
4. Copy the current data directory to the new one
sudo rsync -aP /var/lib/docker/ "/path/to/your/new/docker/root"
sudo cp -rp /var/lib/docker/* "/path/to/your/new/docker/root/"
5. Rename the old docker directory
sudo mv /var/lib/docker /var/lib/docker.old
6. Restart the docker daemon
sudo service docker start
7. Test -> OK -> remove docker.old
docker inspect <image ID>
-> find "WorkDir"
docker run -it --name test_v1 --net=host --mount type=bind,source=/home/nhphuong/catkin_ws,target=/catkin_ws nhphuong91/my_repo:v1.0.1
Remove docker with same image ID
---------------------------------------------
docker image ls --digests=true
-> get sha
docker image rm <docker name>@sha256:...
---------------------------------------------