Skip to content

Commit 22edbf8

Browse files
authored
Merge pull request #188 from Defcon27/master
Added Docker basic commands section-wise & Added commands readme URLs in Docker main page
2 parents 352adcd + 8248f48 commit 22edbf8

File tree

2 files changed

+136
-0
lines changed

2 files changed

+136
-0
lines changed
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
<h1 align="center">Docker Basic Commands</h1>
2+
3+
## Build Images
4+
5+
- Create image using current directory’s Dockerfile <br>
6+
``` docker build -t image-name . ```
7+
8+
- List images<br>
9+
``` docker images ```
10+
11+
<br>
12+
13+
## Running Container
14+
15+
- Create new container from specified image<br>
16+
``` docker run image-name ```
17+
18+
- Assign a name to the container<br>
19+
``` docker run --name nick-name image-name ```
20+
21+
- Run image with an entry point | override existing entrypoint<br>
22+
```docker run image-name cmd```<br>
23+
```docker run image-name --entrypoint cmd```
24+
25+
- Run image in interactive mode<br>
26+
``` docker run -it image-name ```
27+
28+
- Run image in detached mode<br>
29+
``` docker run -d image-name ```
30+
31+
- Run image mapping container's port to the host<br>
32+
``` docker run -p host-port:container-port image-name ```
33+
34+
<br>
35+
36+
## Managing Containers
37+
38+
- List running containers<br>
39+
``` docker ps ```
40+
41+
- List all containers<br>
42+
```docker ps -a```
43+
44+
- Stop one or more running containers<br>
45+
```docker stop containerId```
46+
47+
- Start one or more stopped containers<br>
48+
```docker start containerId```
49+
50+
- Fetch the logs of a container<br>
51+
```docker logs containerId```
52+
53+
- Fetch and follow log output of a container<br>
54+
```docker logs -f containerId```
55+
56+
- Run a command in a running container in interactive mode<br>
57+
```docker exec -it containerId cmd```
58+
59+
- Copy files/folders from container to local filesystem<br>
60+
``` docker cp containerId:/workdir/file.ext .```
61+
62+
- Copy files/folders from local filesystem to container<br>
63+
``` docker cp file.ext containerId:/workdir/```
64+
65+
- Remove container<br>
66+
```docker rm containerId```
67+
68+
- Remove running container<br>
69+
```docker rm -f containerId```
70+
71+
- Remove all running and stopped containers<br>
72+
```docker rm -f $(docker ps -a -q)```
73+
74+
<br>
75+
76+
77+
## Persistant data using Volumes
78+
79+
- Creates a new volume that containers store data<br>
80+
```docker volume create volume-name```
81+
82+
- Display detailed information on one or more volumes<br>
83+
```docker volume inspect volume-name```
84+
85+
- List volumes<br>
86+
```docker volume ls```
87+
88+
- Create a volume and then configure the container to use it<br>
89+
``` docker run -v volume-name:/dir/dir container-name```
90+
91+
- Create mapping between dir in host and container<br>
92+
``` docker run -v $(pwd):/workdir container-name```
93+
94+
95+
96+
97+
<br>
98+
99+
## Managing Images
100+
101+
#### Tagging Images
102+
103+
- Create tag to the image while building<br>
104+
``` docker build -t image-name:tag . ```
105+
106+
- Create tag to the image after building<br>
107+
``` docker image tag src-image:latest dst-image:tag ```
108+
109+
#### Saving & Loading Images
110+
111+
- Save one or more images to a tar archive<br>
112+
``` docker image save -o image-name.tar image-name:tag ```
113+
114+
- Load an image from a tar archive<br>
115+
``` docker image load -i image-name.tar ```
116+
117+
#### Remove Images
118+
119+
- Remove one or more images<br>
120+
``` docker image rm image-name ```<br>
121+
``` docker rmi image-name ```
122+
123+
- Remove all images<br>
124+
``` docker system prune -a ```
125+
126+
- Remove all stopped containers<br>
127+
``` docker container prune ```
128+
129+
- Remove all dangling images<br>
130+
``` docker image prune ```
131+
132+
- Remove all unused containers, networks, dangling and unreferenced images<br>
133+
``` docker system prune ```

Container-orchestration/Docker/readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111

1212

1313
*****************
14+
[`Docker Basic Commands`](docker-basic-commands.md)
1415

16+
[`Docker Complete Commands`](docker-commands.md)
17+
*****************
1518
## 1. Basic concepts of docker - Containers and Images
1619

1720
- Detailed Docker concepts and notes from here - [Docker Concepts](https://github.com/Tikam02/DevOps-Guide/blob/master/Container-orchestration/Docker/docker-concepts.md)

0 commit comments

Comments
 (0)