forked from cheat/cheatsheets
-
Notifications
You must be signed in to change notification settings - Fork 0
/
docker
104 lines (70 loc) · 2.85 KB
/
docker
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# To start the docker daemon:
docker -d
# To build a docker image:
docker build -t <image-tag-name> <path-of-Dockerfile>
# To start a container with an interactive shell:
docker run -ti <image-name> /bin/bash
# To run a docker container in the background:
docker run -d <image-name>
# To "shell" into a running container (docker-1.3+):
docker exec -ti <container-name> bash
# To inspect a running container:
docker inspect <container-name> (or <container-id>)
# To get the process ID for a container:
docker inspect --format {{.State.Pid}} <container-name-or-id>
# To list (and pretty-print) the current mounted volumes for a container:
docker inspect --format='{{json .Volumes}}' <container-id> | python -mjson.tool
# To copy files/folders between a container and your host:
docker cp foo.txt mycontainer:/foo.txt
# To list currently running containers:
docker ps
# To list all containers:
docker ps -a
# To remove all stopped containers:
docker container prune
# To remove all stopped containers:
docker rm $(docker ps -qa)
# To list all images:
docker images
# To only see all images id:
docker image ls -q
# To remove all untagged images:
docker rmi $(docker images | grep "^<none>" | awk '{print $3}')
# To remove all volumes not used by at least one container:
docker volume prune
# To save image as tar archive:
docker save -o <archive-name>.tar <image-name>
# To restore image from a saved tar archive:
docker load -i <archive-name>.tar
# To remove an image:
docker image rm <image-name-or-id>
# To tag an image:
docker image tag <image-name>:<tag-name> <image-name>:<new-tag-name>
# To login into hub.docker.com:
docker login
# To push a docker image into dockerhub repository:
docker push <image-name>:<image-tag-name>
# List all networks daemon knows about:
docker network ls
# Create a specific network:
docker network create "<network_name>"
# Connect a specific container to a network:
docker network connect "<network_id|name>" "<container_id|name>"
# Disconnect a specific container from network:
docker network disconnect "<network_id|name>" "<container_id|name>"
# To see the logs of a background or stopped container:
docker logs <container-id>
# To publish a port of container on localhost:
docker run -p <localhost-port>:<container-port> <image-name>
# To create a docker volume:
docker volume create <volume-name>
# To see information of a docker volume:
docker volume inspect <volume-name>
# To use a volume in the container:
docker run -v <volume-name>:<folder-path-in-container> <image>
# To link current folder between host and container for development:
docker run <image-name> -v $(pwd):<folder-path-in-container> <image>
# To copy a file from the running container to host mechine:
docker cp <container-id>:<path/to/file> <host/copy/path>
# To copy a file from host mechine to the running container:
docker cp <host/copy/path> <container-id>:<path/to/file>