Skip to content

Commit b733416

Browse files
committed
Docker - Complete Cheat Sheet
1 parent fb13463 commit b733416

File tree

1 file changed

+261
-0
lines changed

1 file changed

+261
-0
lines changed
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
---
2+
title : Docker - Complete Cheat Sheet
3+
sidebar_label : Cheat Sheet
4+
---
5+
6+
# Docker - Complete Cheat Sheet
7+
8+
<SubHeading>Learn how to hack Docker via a complete cheat sheet.</SubHeading>
9+
10+
A **[Docker](https://www.docker.com/) Cheat Sheet** provides a quick reference guide for common Docker commands and concepts.
11+
12+
**Docker** is a containerization platform that allows you to package and distribute applications along with their dependencies in containers.
13+
14+
![Docker, complete Cheat Sheet - Tutorial provided by AppSeed](https://github-production-user-asset-6210df.s3.amazonaws.com/51070104/268558520-a87dbf5e-83a8-4daf-9b10-8417b58c60e1.png)
15+
16+
> Here's a **Docker cheat sheet with commonly used commands and concepts**:
17+
18+
## **Docker Commands**
19+
20+
### **Pull an Image**
21+
22+
Download a Docker image from a registry (e.g., Docker Hub).
23+
24+
```bash
25+
$ docker pull image_name:tag
26+
```
27+
28+
### **List Images**
29+
30+
View a list of locally available Docker images.
31+
32+
```bash
33+
$ docker images
34+
```
35+
36+
### **Run a Container**
37+
38+
Start a new container from an image.
39+
40+
```bash
41+
$ docker run image_name:tag
42+
```
43+
44+
- Add `-d` to run in detached mode.
45+
- Use `--name` to specify a custom container name.
46+
- Use `-p` to map ports (e.g., `-p host_port:container_port`).
47+
48+
### **List Containers**
49+
50+
View a list of running containers.
51+
52+
```bash
53+
$ docker ps
54+
```
55+
56+
- Add `-a` to see all containers, including stopped ones.
57+
58+
### **Stop a Container**
59+
60+
Stop a running container gracefully.
61+
62+
```bash
63+
$ docker stop container_id
64+
```
65+
66+
### **Remove a Container**
67+
68+
Delete a stopped container.
69+
70+
```bash
71+
$ docker rm container_id
72+
```
73+
74+
### **Remove an Image**
75+
76+
Delete a Docker image.
77+
78+
```bash
79+
$ docker rmi image_name:tag
80+
```
81+
82+
### **Inspect Container**
83+
84+
View detailed information about a container.
85+
86+
```bash
87+
$ docker inspect container_id
88+
```
89+
90+
## **Docker Compose**
91+
92+
Docker Compose is a tool for defining and running multi-container Docker applications.
93+
94+
### **Create and Start Services**
95+
96+
Start containers defined in a `docker-compose.yml` file.
97+
98+
```bash
99+
$ docker-compose up
100+
```
101+
102+
- Add `-d` to run in detached mode.
103+
104+
### **Stop Services**
105+
106+
Stop containers defined in a `docker-compose.yml` file.
107+
108+
```bash
109+
$ docker-compose down
110+
```
111+
112+
### **List Services**
113+
114+
View a list of services defined in the `docker-compose.yml` file.
115+
116+
```bash
117+
$ docker-compose ps
118+
```
119+
120+
## **Docker Volumes**
121+
122+
Docker volumes are used to persist data between container runs.
123+
124+
### **Create a Volume**
125+
126+
Create a named volume.
127+
128+
```bash
129+
$ docker volume create volume_name
130+
```
131+
132+
### **List Volumes**
133+
134+
View a list of available volumes.
135+
136+
```bash
137+
$ docker volume ls
138+
```
139+
140+
### **Attach a Volume to a Container**
141+
142+
Mount a volume to a container.
143+
144+
```bash
145+
$ docker run -v volume_name:/container_mount_point image_name
146+
```
147+
148+
## **Docker Networks**
149+
150+
Docker networks allow containers to communicate with each other.
151+
152+
### **Create a Network**
153+
154+
Create a custom network.
155+
156+
```bash
157+
$ docker network create network_name
158+
```
159+
160+
### **List Networks**
161+
162+
View a list of available networks.
163+
164+
```bash
165+
$ docker network ls
166+
```
167+
168+
### **Attach a Container to a Network**
169+
170+
Connect a container to a custom network.
171+
172+
```bash
173+
$ docker network connect network_name container_name
174+
```
175+
176+
## **Dockerfile**
177+
178+
A Dockerfile is a script used to create a Docker image.
179+
180+
### **Create a Dockerfile**
181+
182+
Create a Dockerfile in your project directory.
183+
184+
```Dockerfile
185+
# Example Dockerfile
186+
FROM base_image:tag
187+
RUN command_to_run
188+
```
189+
190+
### **Build an Image**
191+
192+
Build a Docker image using a Dockerfile.
193+
194+
```bash
195+
$ docker build -t image_name:tag .
196+
```
197+
198+
## **Additional Docker Commands**
199+
200+
### **Logs**
201+
202+
View container logs.
203+
204+
```bash
205+
$ docker logs container_id
206+
```
207+
208+
### **Exec**
209+
210+
Run a command in a running container.
211+
212+
```bash
213+
$ docker exec -it container_id command
214+
```
215+
216+
### **Prune**
217+
218+
Remove stopped containers, unused networks, and dangling images.
219+
220+
```bash
221+
$ docker system prune
222+
```
223+
224+
### **Login to a Registry**
225+
226+
Log in to a Docker image registry (e.g., Docker Hub).
227+
228+
```bash
229+
$ docker login
230+
```
231+
232+
## ✅ Docker Templates
233+
234+
This section contains a few open-source starters that include production-ready Docker setups:
235+
236+
### 👉 [Django Bootstrap 5 Volt](https://appseed.us/product/volt-dashboard/django/)
237+
238+
Free starter built on top of **Bootstrap 5 and Django** with Database, DB Tools, OAuth via Github and Docker Support.
239+
240+
![Django Bootstrap 5 Volt - Open-source Starter with Docker Support.](https://user-images.githubusercontent.com/51070104/269347618-1f21456d-b0b5-4d4b-9ee5-99ccb6c22188.jpg)
241+
242+
### 👉 [Django Modernize](https://appseed.us/product/modernize-dashboard/django/)
243+
244+
Open-Source Seed Project crafted on top of Modernize **Bootstrap 5 and Django**.
245+
246+
The product comes with session-based authentication, DB tools, and Docker support.
247+
248+
![Django Modernize - Open-source Starter with Docker Support.](https://github-production-user-asset-6210df.s3.amazonaws.com/51070104/270395275-0f223ca7-be26-472d-8af1-6c5e643f4ed6.jpg)
249+
250+
## ✅ In Summary
251+
252+
This cheat sheet provides a quick reference for common Docker commands and concepts.
253+
254+
**Docker** has many more features and options, so be sure to consult the official Docker documentation for more detailed information: https://docs.docker.com/
255+
256+
## ✅ Resources
257+
258+
- 👉 Access [AppSeed](https://appseed.us/) and start your next project
259+
- 👉 [Deploy Projects on Aws, Azure and Digital Ocean](https://www.docs.deploypro.dev/) via **DeployPRO**
260+
- 👉 Create an amazing landing page with [Simpllo, an open-source site builder](https://www.simpllo.com/)
261+
- 👉 [Django App Generator](https://app-generator.dev/django/) - A 2nd generation App Builder

0 commit comments

Comments
 (0)