day5

🧩 Syntax:
[root@dockerlab ~]# docker image ls
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
ubuntu       latest    fd1d8f58e8ae   13 days ago   77.9MB
httpd        2.4       59bcd61b45fd   3 weeks ago   167MB
httpd        latest    59bcd61b45fd   3 weeks ago   167MB
centos       latest    5d0da3dc9764   2 years ago   231MB
[root@dockerlab ~]#

[root@dockerlab ~]# docker image inspect httpd
[
    {
        "Id": "sha256:59bcd61b45fd94a7f19314d259effc3da8b42a0e157263af2246a22c07e96595",
        "RepoTags": [
            "httpd:2.4",
            "httpd:latest"
        ],
        "RepoDigests": [
            "httpd@sha256:5ee9ec089bab71ffcb85734e2f7018171bcb2d6707f402779d3f5b28190bb1af"
        ],
        "Parent": "",
        "Comment": "buildkit.dockerfile.v0",
        "Created": "2024-01-16T18:41:26Z",
        "Container": "",
        "ContainerConfig": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "Tty": false,
            "OpenStdin": false,
            "StdinOnce": false,
            "Env": null,
            "Cmd": null,
            "Image": "",
            "Volumes": null,
            "WorkingDir": "",
            "Entrypoint": null,
            "OnBuild": null,
            "Labels": null
        },
        "DockerVersion": "",
        "Author": "",
        "Config": {
            "Hostname": "",
            "Domainname": "",
            "User": "",
            "AttachStdin": false,
            "AttachStdout": false,
            "AttachStderr": false,
            "ExposedPorts": {
                "80/tcp": {}
            },
            "Tty": false,
================================

[root@dockerlab ~]# docker container run --name mycont -it httpd:latest bash
root@aa831b8cebcb:/usr/local/apache2#
root@aa831b8cebcb:/usr/local/apache2# whoami
root
root@aa831b8cebcb:/usr/local/apache2# pwd
/usr/local/apache2


root@aa831b8cebcb:/usr/local/apache2# ps aux
bash: ps: command not found
root@aa831b8cebcb:/usr/local/apache2# which httpd
/usr/local/apache2/bin/httpd
root@aa831b8cebcb:/usr/local/apache2# which httpd-foreground
/usr/local/bin/httpd-foreground
root@aa831b8cebcb:/usr/local/apache2# ls -ltr /usr/local/apache2/bin/httpd
-rwxr-xr-x. 1 root root 2308672 Jan 31 23:56 /usr/local/apache2/bin/httpd
root@aa831b8cebcb:/usr/local/apache2# ls -ltr /usr/local/bin/httpd-foreground
-rwxr-xr-x. 1 root root 138 Jan 31 23:54 /usr/local/bin/httpd-foreground
root@aa831b8cebcb:/usr/local/apache2#

root@aa831b8cebcb:/usr/local/apache2# httpd -v
Server version: Apache/2.4.58 (Unix)
Server built:   Jan 31 2024 23:55:14
root@aa831b8cebcb:/usr/local/apache2# httpd -V
Server version: Apache/2.4.58 (Unix)
Server built:   Jan 31 2024 23:55:14
Server's Module Magic Number: 20120211:129
Server loaded:  APR 1.7.2, APR-UTIL 1.6.3, PCRE 8.39 2016-06-14
Compiled using: APR 1.7.2, APR-UTIL 1.6.3, PCRE 8.39 2016-06-14
Architecture:   64-bit
Server MPM:     event
  threaded:     yes (fixed thread count)
    forked:     yes (variable process count)
Server compiled with....
 -D APR_HAS_SENDFILE
 -D APR_HAS_MMAP
 -D APR_HAVE_IPV6 (IPv4-mapped addresses enabled)
 -D APR_USE_PROC_PTHREAD_SERIALIZE
 -D APR_USE_PTHREAD_SERIALIZE
 -D SINGLE_LISTEN_UNSERIALIZED_ACCEPT
 -D APR_HAS_OTHER_CHILD
 -D AP_HAVE_RELIABLE_PIPED_LOGS
 -D DYNAMIC_MODULE_LIMIT=256
 -D HTTPD_ROOT="/usr/local/apache2"
 -D SUEXEC_BIN="/usr/local/apache2/bin/suexec"
 -D DEFAULT_PIDLOG="logs/httpd.pid"
 -D DEFAULT_SCOREBOARD="logs/apache_runtime_status"
 -D DEFAULT_ERRORLOG="logs/error_log"
 -D AP_TYPES_CONFIG_FILE="conf/mime.types"
 -D SERVER_CONFIG_FILE="conf/httpd.conf"
root@aa831b8cebcb:/usr/local/apache2#


root@aa831b8cebcb:/usr/local/apache2# cd /usr/local/apache2
root@aa831b8cebcb:/usr/local/apache2# ls
bin  build  cgi-bin  conf  error  htdocs  icons  include  logs  modules
root@aa831b8cebcb:/usr/local/apache2# cd htdocs/
root@aa831b8cebcb:/usr/local/apache2/htdocs# ll
bash: ll: command not found
root@aa831b8cebcb:/usr/local/apache2/htdocs# ls
index.html
root@aa831b8cebcb:/usr/local/apache2/htdocs# cat index.html
<html><body><h1>It works!</h1></body></html>
root@aa831b8cebcb:/usr/local/apache2/htdocs# pwd
/usr/local/apache2/htdocs


root@aa831b8cebcb:/usr/local/apache2/htdocs# ls -l /usr/local/apache2
total 80
drwxr-xr-x. 2 root root 16384 Jan 31 23:56 bin
drwxr-xr-x. 2 root root   167 Jan 31 23:56 build
drwxr-xr-x. 2 root root    78 Jan 31 23:56 cgi-bin
drwxr-xr-x. 4 root root    84 Jan 31 23:56 conf
drwxr-xr-x. 3 root root 16384 Jan 31 23:56 error
drwxr-xr-x. 2 root root    24 Jan 31 23:56 htdocs
drwxr-xr-x. 3 root root 16384 Jan 31 23:56 icons
drwxr-xr-x. 2 root root 16384 Jan 31 23:56 include
drwxr-xr-x. 2 root root     6 Jan 31 23:56 logs
drwxr-xr-x. 2 root root 16384 Jan 31 23:56 modules
root@aa831b8cebcb:/usr/local/apache2/htdocs#

root@aa831b8cebcb:/usr/local/apache2/htdocs#
root@aa831b8cebcb:/usr/local/apache2/htdocs# cd ~
root@aa831b8cebcb:~# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/";
SUPPORT_URL="https://www.debian.org/support";
BUG_REPORT_URL="https://bugs.debian.org/";
root@aa831b8cebcb:~#

root@aa831b8cebcb:~# ps aux
bash: ps: command not found
root@aa831b8cebcb:~# apt-get update
Get:1 http://deb.debian.org/debian bookworm InRelease [151 kB]
Get:2 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB]
Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:4 http://deb.debian.org/debian bookworm/main amd64 Packages [8787 kB]
Get:5 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [12.7 kB]
Get:6 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [137 kB]
Fetched 9188 kB in 1s (6266 kB/s)
Reading package lists... Done
root@aa831b8cebcb:~# apt-get install procps
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libgpm2 libncursesw6 libproc2-0 psmisc
Suggested packages:
  gpm
The following NEW packages will be installed:
  libgpm2 libncursesw6 libproc2-0 procps psmisc
0 upgraded, 5 newly installed, 0 to remove and 0 not upgraded.
Need to get 1178 kB of archives.
After this operation, 3778 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://deb.debian.org/debian bookworm/main amd64 libncursesw6 amd64 6.4-4 [134 kB]
Get:2 http://deb.debian.org/debian bookworm/main amd64 libproc2-0 amd64 2:4.0.2-3 [62.8 kB]
Get:3 http://deb.debian.org/debian bookworm/main amd64 procps amd64 2:4.0.2-3 [709 kB]
Get:4 http://deb.debian.org/debian bookworm/main amd64 libgpm2 amd64 1.20.7-10+b1 [14.2 kB]
Get:5 http://deb.debian.org/debian bookworm/main amd64 psmisc amd64 23.6-1 [259 kB]
Fetched 1178 kB in 0s (34.7 MB/s)
debconf: delaying package configuration, since apt-utils is not installed
Selecting previously unselected package libncursesw6:amd64.
(Reading database ... 8502 files and directories currently installed.)
Preparing to unpack .../libncursesw6_6.4-4_amd64.deb ...
Unpacking libncursesw6:amd64 (6.4-4) ...
Selecting previously unselected package libproc2-0:amd64.
Preparing to unpack .../libproc2-0_2%3a4.0.2-3_amd64.deb ...
Unpacking libproc2-0:amd64 (2:4.0.2-3) ...
Selecting previously unselected package procps.
Preparing to unpack .../procps_2%3a4.0.2-3_amd64.deb ...
Unpacking procps (2:4.0.2-3) ...
Selecting previously unselected package libgpm2:amd64.
Preparing to unpack .../libgpm2_1.20.7-10+b1_amd64.deb ...
Unpacking libgpm2:amd64 (1.20.7-10+b1) ...
Selecting previously unselected package psmisc.
Preparing to unpack .../psmisc_23.6-1_amd64.deb ...
Unpacking psmisc (23.6-1) ...
Setting up libgpm2:amd64 (1.20.7-10+b1) ...
Setting up psmisc (23.6-1) ...
Setting up libproc2-0:amd64 (2:4.0.2-3) ...
Setting up libncursesw6:amd64 (6.4-4) ...
Setting up procps (2:4.0.2-3) ...
Processing triggers for libc-bin (2.36-9+deb12u4) .

=========
root@aa831b8cebcb:~# ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.3   4188  3528 pts/0    Ss   17:44   0:00 bash
root         205  0.0  0.4   8088  3964 pts/0    R+   17:51   0:00 ps aux
root@aa831b8cebcb:~#


root@aa831b8cebcb:~# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
4: eth0@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
root@aa831b8cebcb:~#

========================================
[root@dockerlab ~]# docker container ls
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@dockerlab ~]# docker container ls -a
CONTAINER ID   IMAGE          COMMAND   CREATED          STATUS                       PORTS     NAMES
aa831b8cebcb   httpd:latest   "bash"    11 minutes ago   Exited (127) 9 seconds ago             mycont
[root@dockerlab ~]#
[root@dockerlab ~]# docker container rm aa831b8cebcb
aa831b8cebcb
[root@dockerlab ~]# docker container ls -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@dockerlab ~]#

===========================================
[root@dockerlab ~]# docker container run --name webserver httpd:latest
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' directive globally to suppress this message
[Wed Feb 07 17:57:56.413128 2024] [mpm_event:notice] [pid 1:tid 139968043865984] AH00489: Apache/2.4.58 (Unix) configured -- resuming normal operations
[Wed Feb 07 17:57:56.413255 2024] [core:notice] [pid 1:tid 139968043865984] AH00094: Command line: 'httpd -D FOREGROUND'

^C[Wed Feb 07 17:58:13.367197 2024] [mpm_event:notice] [pid 1:tid 139968043865984] AH00491: caught SIGTERM, shutting down
[root@dockerlab ~]#
[root@dockerlab ~]#
[root@dockerlab ~]#
[root@dockerlab ~]#
[root@dockerlab ~]# docker container run --name webserver -d httpd:latest
docker: Error response from daemon: Conflict. The container name "/webserver" is already in use by container "b15b0d31a89bc49f52190283743c90f757c92105287441940fa4107289431fe0". You have to remove (or rename) that container to be able to reuse that name.
See 'docker run --help'.
[root@dockerlab ~]#
[root@dockerlab ~]# docker container run --name webservertest -d httpd:latest
560f36ccceda52f2d6b2ed7633dccb35e04443ab7ee59dccd42ca3871973db2b
[root@dockerlab ~]#


==============


[root@dockerlab ~]# docker container inspect 560f36ccceda
[
    {
        "Id": "560f36ccceda52f2d6b2ed7633dccb35e04443ab7ee59dccd42ca3871973db2b",
        "Created": "2024-02-07T17:58:34.772908466Z",
        "Path": "httpd-foreground",
        "Args": [],
        "State": {
            "Stat

===


            "SandboxKey": "/var/run/docker/netns/80468edcb6dc",
            "SecondaryIPAddresses": null,
            "SecondaryIPv6Addresses": null,
            "EndpointID": "41c5f72331aa42fa4c15f50b5c3340559c0ebc64fdcc38252d9c61c061ecc0c6",
            "Gateway": "172.17.0.1",
            "GlobalIPv6Address": "",
            "GlobalIPv6PrefixLen": 0,
            "IPAddress": "172.17.0.2",
            "IPPrefixLen": 16,
            "IPv6Gateway": "",
            "MacAddress": "02:42:ac:11:00:02",


[root@dockerlab ~]# docker container inspect 560f36ccceda | grep 172
            "Gateway": "172.17.0.1",
            "IPAddress": "172.17.0.2",
                    "Gateway": "172.17.0.1",
                    "IPAddress": "172.17.0.2",
[root@dockerlab ~]#

[root@dockerlab ~]# curl http://172.17.0.2
<html><body><h1>It works!</h1></body></html>
[root@dockerlab ~]#

======
[root@dockerlab ~]# docker container exec webservertest cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/";
SUPPORT_URL="https://www.debian.org/support";
BUG_REPORT_URL="https://bugs.debian.org/";
[root@dockerlab ~]#
=====
[root@dockerlab ~]# docker container exec webservertest ip a
OCI runtime exec failed: exec failed: unable to start container process: exec: "ip": executable file not found in $PATH: unknown
[root@dockerlab ~]#

root@560f36ccceda:/usr/local/apache2# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/";
SUPPORT_URL="https://www.debian.org/support";
BUG_REPORT_URL="https://bugs.debian.org/";
root@560f36ccceda:/usr/local/apache2#
root@560f36ccceda:/usr/local/apache2# which ip
root@560f36ccceda:/usr/local/apache2# which ps
root@560f36ccceda:/usr/local/apache2# apt update
Get:1 http://deb.debian.org/debian bookworm InRelease [151 kB]
Get:2 http://deb.debian.org/debian bookworm-updates InRelease [52.1 kB]
Get:3 http://deb.debian.org/debian-security bookworm-security InRelease [48.0 kB]
Get:4 http://deb.debian.org/debian bookworm/main amd64 Packages [8787 kB]
Get:5 http://deb.debian.org/debian bookworm-updates/main amd64 Packages [12.7 kB]
Get:6 http://deb.debian.org/debian-security bookworm-security/main amd64 Packages [137 kB]
Fetched 9188 kB in 2s (6055 kB/s)
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.
root@560f36ccceda:/usr/local/apache2
================
root@560f36ccceda:/usr/local/apache2# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
8: eth0@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
root@560f36ccceda:/usr/local/apache2#

root@560f36ccceda:/usr/local/apache2#
root@560f36ccceda:/usr/local/apache2# which ip
/usr/sbin/ip
root@560f36ccceda:/usr/local/apache2# which ps
/usr/bin/ps


root@560f36ccceda:/usr/local/apache2# ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.4   5860  4648 ?        Ss   17:58   0:00 httpd -DFOREGROUND
www-data       8  0.0  0.4 807160  4152 ?        Sl   17:58   0:00 httpd -DFOREGROUND
www-data       9  0.0  0.3 807096  3700 ?        Sl   17:58   0:00 httpd -DFOREGROUND
www-data      10  0.0  0.3 807096  3700 ?        Sl   17:58   0:00 httpd -DFOREGROUND
root         103  0.0  0.3   4188  3464 pts/0    Ss   18:05   0:00 bash
root         443  0.0  0.4   8088  3948 pts/0    R+   18:08   0:00 ps aux
root@560f36ccceda:/usr/local/apache2#


============
root@560f36ccceda:/usr/local/apache2# cd htdocs/
root@560f36ccceda:/usr/local/apache2/htdocs# ls
index.html
root@560f36ccceda:/usr/local/apache2/htdocs# cat index.html
<html><body><h1>It works!</h1></body></html>
root@560f36ccceda:/usr/local/apache2/htdocs#

[root@dockerlab ~]# docker container exec  webservertest ps aux
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root           1  0.0  0.4   5860  4648 ?        Ss   17:58   0:00 httpd -DFOREGROUND
www-data       8  0.0  0.4 807160  4164 ?        Sl   17:58   0:00 httpd -DFOREGROUND
www-data       9  0.0  0.3 807096  3700 ?        Sl   17:58   0:00 httpd -DFOREGROUND
www-data      10  0.0  0.3 807096  3700 ?        Sl   17:58   0:00 httpd -DFOREGROUND
root         449 50.0  0.4   8088  3928 ?        Rs   18:11   0:00 ps aux
[root@dockerlab ~]#
==============
[root@dockerlab ~]# docker container exec  webservertest ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
       valid_lft forever preferred_lft forever
8: eth0@if9: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default
    link/ether 02:42:ac:11:00:02 brd ff:ff:ff:ff:ff:ff link-netnsid 0
    inet 172.17.0.2/16 brd 172.17.255.255 scope global eth0
       valid_lft forever preferred_lft forever
[root@dockerlab ~]#

[root@dockerlab ~]# docker container  ls
CONTAINER ID   IMAGE          COMMAND              CREATED          STATUS          PORTS     NAMES
560f36ccceda   httpd:latest   "httpd-foreground"   16 minutes ago   Up 16 minutes   80/tcp    webservertest
[root@dockerlab ~]#
[root@dockerlab ~]#
[root@dockerlab ~]# docker container stop 560f36ccceda
560f36ccceda
[root@dockerlab ~]# docker container  ls
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
[root@dockerlab ~]#

===========
[root@dockerlab ~]# docker container run  --name webserver1 -d -p 8080:80 httpd:latest
97da42bc810ddc1b6a93842e789fce6dcec947c3af6451efe4d338845336f5b7
[root@dockerlab ~]# docker container ls -a
CONTAINER ID   IMAGE          COMMAND              CREATED          STATUS          PORTS                                   NAMES
97da42bc810d   httpd:latest   "httpd-foreground"   11 seconds ago   Up 10 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp   webserver1
[root@dockerlab ~]#

[root@dockerlab ~]# docker container run  --name webserver1 -d -p 8080:80 httpd:latest
97da42bc810ddc1b6a93842e789fce6dcec947c3af6451efe4d338845336f5b7
[root@dockerlab ~]# docker container ls -a
CONTAINER ID   IMAGE          COMMAND              CREATED          STATUS          PORTS                                   NAMES
97da42bc810d   httpd:latest   "httpd-foreground"   11 seconds ago   Up 10 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp   webserver1
[root@dockerlab ~]#
[root@dockerlab ~]# docker container run  --name webserver2 -d -p 8081:80 httpd:latest
48c3aac7f409b62dbded215e0d2237b65836d1648654d88f44638d77ed3b4c55
[root@dockerlab ~]# docker container run  --name webserver3 -d -p 8082:80 httpd:latest
5cbdc204eb295182d89ab9526ad593d1997470512d45955468451fe49dc13c79
[root@dockerlab ~]#
[root@dockerlab ~]# docker container ls -a
CONTAINER ID   IMAGE          COMMAND              CREATED              STATUS              PORTS                                   NAMES
5cbdc204eb29   httpd:latest   "httpd-foreground"   5 seconds ago        Up 3 seconds        0.0.0.0:8082->80/tcp, :::8082->80/tcp   webserver3
48c3aac7f409   httpd:latest   "httpd-foreground"   18 seconds ago       Up 16 seconds       0.0.0.0:8081->80/tcp, :::8081->80/tcp   webserver2
97da42bc810d   httpd:latest   "httpd-foreground"   About a minute ago   Up About a minute   0.0.0.0:8080->80/tcp, :::8080->80/tcp   webserver1
[root@dockerlab ~]#


[root@dockerlab ~]# curl http://172.17.0.2
<html><body><h1>It works!</h1></body></html>
[root@dockerlab ~]#

[root@dockerlab ~]# curl http://172.17.0.3
<html><body><h1>It works!</h1></body></html>
[root@dockerlab ~]#