Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #---------------------------------------------------- httpd image pull --------------------------------------------#
- [ec2-user@ip-172-31-41-59 ~]$ docker image ls
- REPOSITORY TAG IMAGE ID CREATED SIZE
- httpd 2-alpine3.18 d7544b312621 11 days ago 59.1MB
- httpd 2.4.57-alpine d7544b312621 11 days ago 59.1MB
- httpd alpine d7544b312621 11 days ago 59.1MB
- httpd 2.4-bullseye b4f91978e2cc 11 days ago 145MB
- httpd 2.4.57 b4f91978e2cc 11 days ago 145MB
- httpd latest b4f91978e2cc 11 days ago 145MB
- #---------------------------------------------------- Image Inspection --------------------------------------------#
- [ec2-user@ip-172-31-41-59 ~]$ docker image inspect --format='{{json .Config.Cmd}}' httpd:alpine
- ["httpd-foreground"]
- [ec2-user@ip-172-31-41-59 ~]$ docker image inspect --format='{{json .Config.Cmd}}' httpd
- ["httpd-foreground"]
- [ec2-user@ip-172-31-41-59 ~]$ docker image ls ubuntu
- REPOSITORY TAG IMAGE ID CREATED SIZE
- ubuntu 18.04 97ba4bbc97fc 10 days ago 63.2MB
- [ec2-user@ip-172-31-41-59 ~]$ docker image inspect --format='{{json .Config.Cmd}}' ubuntu:18.04
- ["/bin/bash"]
- #---------------------------------------------------- Container Creation --------------------------------------------#
- [ec2-user@ip-172-31-41-59 ~]$ docker container run --name container1 -it ubuntu:18.04
- root@13a2dfb944f6:/#
- root@13a2dfb944f6:/#
- root@13a2dfb944f6:/#
- root@13a2dfb944f6:/#
- [ec2-user@ip-172-31-41-59 ~]$ docker container run --name webserver1 -d httpd
- f801695a2a69c52f87553767cdb7f8d74b132c92d8af8fcc4ee537b812361bc0
- [ec2-user@ip-172-31-41-59 ~]$ docker container inspect --format='{{range .NetworkSettings.Networks}}{{println .IPAddress}}{{end}}' webserver1
- 172.17.0.2
- [ec2-user@ip-172-31-41-59 ~]$ curl http://172.17.0.2
- <html><body><h1>It works!</h1></body></html>
- [ec2-user@ip-172-31-41-59 ~]$ docker container run -p 8080:80 -d --name webserver2 httpd
- 2b81735db75bbe62732b4a3a8295e342ec32dee20b4bdc97e3ef25f5432e0b20
- [ec2-user@ip-172-31-41-59 ~]$ docker container inspect --format='{{range .NetworkSettings.Networks}}{{println .IPAddress}}{{end}}' webserver2
- 172.17.0.3
- [ec2-user@ip-172-31-41-59 ~]$ curl http://65.0.30.0:8080
- <html><body><h1>It works!</h1></body></html>
- #---------------------------------------------------- Docker exec --------------------------------------------#
- [ec2-user@ip-172-31-41-59 ~]$ docker exec webserver1 date
- Tue May 23 09:11:58 UTC 2023
- [ec2-user@ip-172-31-41-59 ~]$
- [ec2-user@ip-172-31-41-59 ~]$ docker exec webserver1 ifconfig
- OCI runtime exec failed: exec failed: unable to start container process: exec: "ifconfig": executable file not found in $PATH: unknown
- [ec2-user@ip-172-31-41-59 ~]$
- [ec2-user@ip-172-31-41-59 ~]$
- [ec2-user@ip-172-31-41-59 ~]$ docker exec webserver1 ping
- OCI runtime exec failed: exec failed: unable to start container process: exec: "ping": executable file not found in $PATH: unknown
- [ec2-user@ip-172-31-41-59 ~]$ docker container exec -it webserver2 bash
- root@2b81735db75b:/usr/local/apache2#
- root@2b81735db75b:/usr/local/apache2# apt update && apt install net-tools vim procps -y &> /dev/null
- Get:1 http://deb.debian.org/debian bullseye InRelease [116 kB]
- Get:2 http://deb.debian.org/debian-security bullseye-security InRelease [48.4 kB]
- Get:3 http://deb.debian.org/debian bullseye-updates InRelease [44.1 kB]
- Get:4 http://deb.debian.org/debian bullseye/main amd64 Packages [8183 kB]
- Get:5 http://deb.debian.org/debian-security bullseye-security/main amd64 Packages [243 kB]
- Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [14.6 kB]
- Fetched 8649 kB in 2s (5429 kB/s)
- Reading package lists... Done
- Building dependency tree... Done
- Reading state information... Done
- All packages are up to date.
- eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
- inet 172.17.0.3 netmask 255.255.0.0 broadcast 172.17.255.255
- ether 02:42:ac:11:00:03 txqueuelen 0 (Ethernet)
- RX packets 731 bytes 18132004 (17.2 MiB)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 386 bytes 30025 (29.3 KiB)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
- inet 127.0.0.1 netmask 255.0.0.0
- loop txqueuelen 1000 (Local Loopback)
- RX packets 0 bytes 0 (0.0 B)
- RX errors 0 dropped 0 overruns 0 frame 0
- TX packets 0 bytes 0 (0.0 B)
- TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
- root@2b81735db75b:/usr/local/apache2# echo "<h1><center>I'm in a devops class</h1></center>" > /usr/local/apache2/htdocs
- /index.html
- root@2b81735db75b:/usr/local/apache2# ps aux
- USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
- root 1 0.0 0.4 6000 4448 ? Ss 09:06 0:00 httpd -DFOREGROUND
- www-data 8 0.0 0.3 807220 3260 ? Sl 09:06 0:00 httpd -DFOREGROUND
- www-data 9 0.0 0.3 807220 3260 ? Sl 09:06 0:00 httpd -DFOREGROUND
- www-data 10 0.0 0.3 807284 3692 ? Sl 09:06 0:00 httpd -DFOREGROUND
- www-data 92 0.0 0.3 807284 3696 ? Sl 09:08 0:00 httpd -DFOREGROUND
- root 120 0.0 0.3 4152 3248 pts/0 Ss 09:22 0:00 bash
- root 573 0.0 0.2 6756 2816 pts/0 R+ 09:24 0:00 ps aux
- [ec2-user@ip-172-31-41-59 ~]$ curl http://65.0.30.0:8080
- <h1><center>I'm in a devops class</h1></center>
- #---------------------------------------------------- Deleting the container --------------------------------------------#
- [ec2-user@ip-172-31-41-59 ~]$ docker container ls -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 2b81735db75b httpd "httpd-foreground" 20 minutes ago Up 20 minutes 0.0.0.0:8080->80/tcp, :::8080->80/tcp webserver2
- f801695a2a69 httpd "httpd-foreground" 39 minutes ago Up 39 minutes 80/tcp webserver1
- 13a2dfb944f6 ubuntu:18.04 "/bin/bash" About an hour ago Exited (0) About an hour ago
- [ec2-user@ip-172-31-41-59 ~]$ docker container stop webserver1
- webserver1
- [ec2-user@ip-172-31-41-59 ~]$ docker container stop webserver2
- webserver2
- [ec2-user@ip-172-31-41-59 ~]$ docker container rm webserver2
- webserver2
- [ec2-user@ip-172-31-41-59 ~]$ docker container rm webserver1
- webserver1
- [ec2-user@ip-172-31-41-59 ~]$ docker container rm container1
- container1
- [ec2-user@ip-172-31-41-59 ~]$
- [ec2-user@ip-172-31-41-59 ~]$ docker container ls -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- [ec2-user@ip-172-31-41-59 ~]$
- #---------------------------------------------------- Bind mounting --------------------------------------------#
- [ec2-user@ip-172-31-41-59 ~]$ docker container run --name webserver1 -p 8080:80 -d -v /home/ec2-user/site1:/usr/local/apache2/htdocs httpd
- c4cc32ad018c95a4c819edf5fcc1f0d61bb1800118e9468bb2d9c1ad1f9fd829
- [ec2-user@ip-172-31-41-59 ~]$
- [ec2-user@ip-172-31-41-59 ~]$[ec2-user@ip-172-31-41-59 ~]$ docker container run --name webserver2 -p 8081:80 -d -v /home/ec2-user/site2:/usr/local/apache2/htdocs httpd
- f5bf2c6936343d41d3db6ea07385c7ebcf16187fb6e3f0a4244c71bd7d20a5d3
- [ec2-user@ip-172-31-41-59 ~]$
- [ec2-user@ip-172-31-41-59 ~]$
- ec2-user@ip-172-31-41-59 ~]$ docker container ls
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- f5bf2c693634 httpd "httpd-foreground" About a minute ago Up About a minute 0.0.0.0:8081->80/tcp, :::8081->80/tcp webserver2
- c4cc32ad018c httpd "httpd-foreground" 3 minutes ago Up 3 minutes 0.0.0.0:8080->80/tcp, :::8080->80/tcp webserver1
- [ec2-user@ip-172-31-41-59 ~]$
- #---------------------------------------------------- Nginx doc root --------------------------------------------#
- [ec2-user@ip-172-31-41-59 ~]$ docker image pull nginx:latest
- latest: Pulling from library/nginx
- f03b40093957: Pull complete
- 0972072e0e8a: Pull complete
- a85095acb896: Pull complete
- d24b987aa74e: Pull complete
- 6c1a86118ade: Pull complete
- 9989f7b33228: Pull complete
- Digest: sha256:f5747a42e3adcb3168049d63278d7251d91185bb5111d2563d58729a5c9179b0
- Status: Downloaded newer image for nginx:latest
- docker.io/library/nginx:latest
- [ec2-user@ip-172-31-41-59 ~]$
- [ec2-user@ip-172-31-41-59 ~]$ docker image ls nginx:latest
- REPOSITORY TAG IMAGE ID CREATED SIZE
- nginx latest a7be6198544f 52 minutes ago 142MB
- [ec2-user@ip-172-31-41-59 ~]$
- [ec2-user@ip-172-31-41-59 ~]$ docker image inspect --format='{{json .Config.Cmd}}' nginx
- ["nginx","-g","daemon off;"]
- [ec2-user@ip-172-31-41-59 ~]$ docker container run --name webserver3 -p 8082:80 -d -v /home/ec2-user/site3:/usr/share/nginx/html nginx
- ca7dbbd4987d80775b5646ecffb2ed078afa3c1f77d373ac3f2c21d70ff7864b
- [ec2-user@ip-172-31-41-59 ~]$ docker container run --name webserver4 -p 8083:80 -d -v /home/ec2-user/site4:/usr/share/nginx/html nginx
- 97b2e89aa2e9f21fe9f9e94301d2c3273c6cec377571813694b8060bd22d0209
- [ec2-user@ip-172-31-41-59 ~]$ docker container ls -a
- CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
- 97b2e89aa2e9 nginx "/docker-entrypoint.…" 2 minutes ago Up 2 minutes 0.0.0.0:8083->80/tcp, :::8083->80/tcp webserver4
- ca7dbbd4987d nginx "/docker-entrypoint.…" 3 minutes ago Up 3 minutes 0.0.0.0:8082->80/tcp, :::8082->80/tcp webserver3
- f5bf2c693634 httpd "httpd-foreground" 47 minutes ago Up 47 minutes 0.0.0.0:8081->80/tcp, :::8081->80/tcp webserver2
- c4cc32ad018c httpd "httpd-foreground" 49 minutes ago Up 49 minutes 0.0.0.0:8080->80/tcp, :::8080->80/tcp webserver1
Advertisement
Add Comment
Please, Sign In to add comment