-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathdockerday2
More file actions
157 lines (124 loc) Β· 3.92 KB
/
Copy pathdockerday2
File metadata and controls
157 lines (124 loc) Β· 3.92 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
1 curl -fsSL https://get.docker.com -o install-docker.sh
2 ls
3 sh install-docker.sh
4 docker --version
5 docker ps
6 docker ps -a
7 docker images
8 docker run hello-world
9 docker ps
10 docker ps -a
11 docker images
12 docker run -it ubuntu
13 docker ps
14 docker ps -a
15 docker start 8aafca4a6f92
16 docker ps
17 docker exec -it 8aafca4a6f92 bin/bash
18 docker ps
19 docker images
20 docker commit 8aafca4a6f92 anuragiswrongimage
21 docker images
22 docker pull nginx
23 docker images
24 docker run nginx
25 docker ps
26 docker ps -a
27 docker run -p 80:80 nginx
28 docker run --name docker-nginx -p 80:80 nginx
29 docker ps -a
30 docker run --name -d docker-nginx -p 80:80 nginx
31 docker run --name docker-nginx -d -p 80:80 nginx
32 docker run --name docker-nginx1 -d -p 80:80 nginx
33 history
# π³ **Docker Installation & Basic Commands β Practice Guide**
> π **Hands-on Docker practice on Linux**
> Learn how to install Docker, manage containers & images, and test using **Nginx**.
---
## πΉ **1. Install Docker**
```bash
curl -fsSL https://get.docker.com -o install-docker.sh
π Explanation:
β‘οΈ Downloads the official Docker installation script and saves it as install-docker.sh.
ls
π Explanation:
β‘οΈ Verifies that install-docker.sh is downloaded.
sh install-docker.sh
π Explanation:
β‘οΈ Installs Docker Engine on your Linux system.
πΉ 2. Verify Docker Installation
docker --version
π Explanation:
β‘οΈ Confirms Docker installation and displays the installed version.
πΉ 3. Container Management Commands
docker ps
π Explanation:
β‘οΈ Shows only running containers.
docker ps -a
π Explanation:
β‘οΈ Shows all containers (running + stopped).
πΉ 4. Image Management Commands
docker images
π Explanation:
β‘οΈ Lists all locally available Docker images.
πΉ 5. Run Test Container
docker run hello-world
π Explanation:
β‘οΈ Runs a test container to verify Docker is working correctly.
πΉ 6. Run Ubuntu Container (Interactive Mode)
docker run -it ubuntu
π Explanation:
β‘οΈ Starts an Ubuntu container in interactive terminal mode.
πΉ 7. Start Existing Container
docker start <container_id>
β
Example:
docker start 8aafca4a6f92
π Explanation:
β‘οΈ Starts a previously stopped container.
πΉ 8. Access Container Terminal
docker exec -it <container_id> /bin/bash
β
Example:
docker exec -it 8aafca4a6f92 /bin/bash
π Explanation:
β‘οΈ Opens a bash terminal inside a running container.
πΉ 9. Create Image from Container
docker commit <container_id> <new_image_name>
β
Example:
docker commit 8aafca4a6f92 anuragiswrongimage
π Explanation:
β‘οΈ Creates a new Docker image from the container state.
πΉ 10. Pull Nginx Image
docker pull nginx
π Explanation:
β‘οΈ Downloads the official Nginx image from Docker Hub.
πΉ 11. Run Nginx Container
docker run nginx
π Explanation:
β‘οΈ Runs Nginx container (not accessible externally yet).
πΉ 12. Run Nginx with Port Mapping
docker run -p 80:80 nginx
π Explanation:
β‘οΈ Maps container port 80 to host port 80
β‘οΈ Access via browser: http://localhost
πΉ 13. Run Nginx in Background with Name
docker run --name docker-nginx -d -p 80:80 nginx
π Explanation:
--name β Assigns container name
-d β Runs in background (detached mode)
-p 80:80 β Port mapping
β 14. Common Mistake
π« Wrong Command
docker run --name -d docker-nginx -p 80:80 nginx
β
Correct Command
docker run --name docker-nginx -d -p 80:80 nginx
β οΈ Reason:
β‘οΈ --name must be followed immediately by the container name.
β‘οΈ Flag order matters!
πΉ 15. Command History
history
π Explanation:
β‘οΈ Displays previously executed commands (useful for revision & troubleshooting).
π― Practice Tip
http://localhost
β
If you see the Nginx Welcome Page,
π Docker networking is working perfectly! π