{"id":5533,"date":"2023-09-01T21:55:34","date_gmt":"2023-09-01T19:55:34","guid":{"rendered":"http:\/\/miro.borodziuk.eu\/?p=5533"},"modified":"2024-02-22T13:38:46","modified_gmt":"2024-02-22T12:38:46","slug":"understanding-and-using-containers","status":"publish","type":"post","link":"http:\/\/miro.borodziuk.eu\/index.php\/2023\/09\/01\/understanding-and-using-containers\/","title":{"rendered":"Understanding and Using Containers"},"content":{"rendered":"<p>.<\/p>\n<p><!--more--><\/p>\n<p><span style=\"color: #3366ff\">What is a Container<\/span><\/p>\n<ul>\n<li>A container is a self-contained ready-to-run application<\/li>\n<li>This is what makes it different from a virtual machine!<\/li>\n<li>Containers have all on board that is required to start the application<\/li>\n<li>To start a container, a container runtime is required<\/li>\n<li>The container runtime is running on a host platform and establishes communication between the local host kernel and the container<\/li>\n<li>So, all containers, no matter what they do, run on top<br \/>\nof the same local host kernel<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Container Components<\/span><\/p>\n<ul>\n<li><em>Images<\/em> are read-only environments that contain the runtime environment, which includes the application and all libraries it requires<\/li>\n<li><em>Containers<\/em> are the isolated runtime environments where the application is running. By using namespaces the containers can be offered as a strictly isolated environment<\/li>\n<li><em>Registries<\/em> are used to store images. Docker Hub is a common registry, other registries exist (like quay.io) and private registries can be created also<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Containers are Linux!<\/span><\/p>\n<ul>\n<li>Containers are based on features offered by the Linux<br \/>\noperating system<\/li>\n<li>Linux Kernel Namespaces provide strict isolation between system components at different levels\n<ul>\n<li>network<\/li>\n<li>file<\/li>\n<li>users<\/li>\n<li>processes<\/li>\n<li>IPCs<\/li>\n<\/ul>\n<\/li>\n<li>Linux CGroups offer resource allocation and limitation<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Container Runtimes<\/span><\/p>\n<ul>\n<li>The container runtime allows for starting and running the container on top of the host OS<\/li>\n<li>The container runtime is responsible for all parts of running the container which are not already a part of the running container program itself<\/li>\n<li>Different container runtime solutions exist\n<ul>\n<li>docker<\/li>\n<li>Ixc<\/li>\n<li>runc<\/li>\n<li>cri-o<\/li>\n<li>containerd<\/li>\n<\/ul>\n<\/li>\n<li>These runtimes are included in the different container solutions<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">The OCI<\/span><\/p>\n<ul>\n<li>OCI is the Open Containers Initiative (https:\/\/opencontainers.org)<\/li>\n<li>It standardizes the use of containers\n<ul>\n<li>The image-spec defines how to package a container in a &#8220;filesystem bundle&#8221;<\/li>\n<li>The runtime-spec defines how to run that filesystem in a container<\/li>\n<\/ul>\n<\/li>\n<li>OCI standardization ensures compatibility between containers, no matter which environment they originally come from<\/li>\n<li>The result is that for instance images made for Docker work without modifications in Red Hat Podman<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Docker<\/span><\/p>\n<ul>\n<li><em>Docker<\/em> is important in the container landscape, but Docker is NOT the only way to run containers<\/li>\n<li>When it started in 2013, Docker offered the following:\n<ul>\n<li>Container image format<\/li>\n<li>Dockerfile, which is a method for building container images<\/li>\n<li>A way to manage container images<\/li>\n<li>A way to run containers<\/li>\n<li>A way to manage container instances<\/li>\n<li>A solution to share container images<\/li>\n<\/ul>\n<\/li>\n<li><em>Podman<\/em> is the main alternative to Docker<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Alternatives to Docker<\/span><\/p>\n<ul>\n<li>With the launch of RHEL 8, Red Hat started offering <em>Podman<\/em> as an alternative to Docker\n<ul>\n<li><em>Podman<\/em> runs containers without the need of having a daemon directly on top of the cri-o container runtime<\/li>\n<li><em>Buildah<\/em> is the related service that is used for managing container images<\/li>\n<\/ul>\n<\/li>\n<li>Other solutions for running containers also exist\n<ul>\n<li><em>LXC<\/em> is a Linux-native container runtime<\/li>\n<li><em>systemd-nspawn<\/em> offers containers integrated in Systemd<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Registries<\/span><\/p>\n<ul>\n<li>Container registries are used to provide access to container images<\/li>\n<li>Registries make distribution of containers easier: anyone can publish images on public registries<\/li>\n<li>Docker Hub (hub.docker.com) is the biggest registry<\/li>\n<li>Other registries exist as well, like quay.io<\/li>\n<li>It&#8217;s also possible to create private registries<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Accessing Registries<\/span><\/p>\n<ul>\n<li>Access to registries is normally free<\/li>\n<li>In some cases, additional authorization is required and you&#8217;ll need an account to access registry contents<\/li>\n<li>On Docker Hub, an account gives access to additional features\n<ul>\n<li>Higher image pull limit<\/li>\n<li>Web hooks connecting to GitHub<\/li>\n<\/ul>\n<\/li>\n<li>Use the browser-based login, or <code>docker login<\/code> from the command line<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Starting Containers<\/span><\/p>\n<ul>\n<li>Many environments are available, let&#8217;s look at Docker<\/li>\n<li>To use containers on RHEL 8 and related distributions, you can use podman instead of docker<\/li>\n<li>Use <code>dnf install -y container-tools<\/code> to install podman and related utilities<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Installing Docker on Ubuntu<\/span><\/p>\n<ul>\n<li><code>sudo apt-get update<\/code><\/li>\n<li><code>sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common<\/code><\/li>\n<li><code>curl -fsSL https:\/\/download.docker.com\/linux\/ubuntu\/gpg | sudo apt-key add -<\/code><\/li>\n<li><code>sudo apt-key fingerprint OEBFCD88<\/code><\/li>\n<li><code>sudo add-apt-repository \"deb [arch=amd64] https:\/\/download.docker.com\/linux\/ubuntu $(Isb_release -cs) stable\"<\/code><\/li>\n<li><code>sudo apt-get update<\/code><\/li>\n<li><code>sudo apt-get install docker-ce docker-ce-cli containerd.io<\/code><\/li>\n<li><code>sudo docker run hello-world<\/code><\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Running a Container<\/span><\/p>\n<ul>\n<li><code>mkdir -p \/var\/www\/html <\/code><\/li>\n<li><code>echo hello from docker &gt;&gt; \/var\/www\/html\/index.html<\/code><\/li>\n<li><code>docker run -d -p 8080:80 --name=\"myapache\" -v \/var\/www\/html:\/var\/www\/html httpd<\/code><\/li>\n<li><code>docker ps<\/code><\/li>\n<li><code>ss -tunap | grep 8080<\/code><\/li>\n<li><code>curl http:\/\/localhost:8080<\/code><\/li>\n<\/ul>\n<pre class=\"lang:default decode:true \">[root@controller \/]# mkdir -p \/var\/www\/html\r\n\r\n[root@controller \/]# echo hello from docker &gt;&gt; \/var\/www\/html\/index.html\r\n\r\n[root@controller \/]# cat \/var\/www\/html\/index.html\r\nhello from docker\r\n\r\n[root@controller \/]# docker run -d -p 8080:80 --name=\"myapache\" -v \/var\/www\/html:\/var\/www\/html httpd\r\nUnable to find image 'httpd:latest' locally\r\nlatest: Pulling from library\/httpd\r\ne1caac4eb9d2: Pull complete\r\n87b0fe460fd9: Pull complete\r\n4f4fb700ef54: Pull complete\r\n9cebd3e3b523: Pull complete\r\ne9304da947c5: Pull complete\r\nb60d4b66b268: Pull complete\r\nDigest: sha256:104f07de17ee186c8f37b9f561e04fbfe4cf080d78c6e5f3802fd08fd118c3da\r\nStatus: Downloaded newer image for httpd:latest\r\n132a8601bc20a2fa997a19438087c412c049f6ea39dfbe7e7591aeb19f50269a\r\n\r\n[root@controller \/]# docker ps\r\nCONTAINER ID   IMAGE     COMMAND              CREATED          STATUS          PORTS                                   NAMES\r\n132a8601bc20   httpd     \"httpd-foreground\"   37 seconds ago   Up 34 seconds   0.0.0.0:8080-&gt;80\/tcp, :::8080-&gt;80\/tcp   myapache\r\n\r\n[root@controller \/]# ss -tunap | grep 8080\r\ntcp   LISTEN    0      2048                0.0.0.0:8080                 0.0.0.0:*     users:((\"docker-proxy\",pid=346482,fd=4))         \r\ntcp   LISTEN    0      2048                   [::]:8080                    [::]:*     users:((\"docker-proxy\",pid=346490,fd=4))         \r\n\r\n[root@controller \/]# curl http:\/\/localhost:8080\r\n&lt;html&gt;&lt;body&gt;&lt;h1&gt;It works!&lt;\/h1&gt;&lt;\/body&gt;&lt;\/html&gt;\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Running Another Container<\/span><\/p>\n<ul>\n<li><code>docker run -it busybox<\/code> will start the busybox container with an interactive terminal to the entrypoint application<\/li>\n<li><code>Ctrl-p, Ctrl-q<\/code> to disconnect and keep it running<\/li>\n<li><code>exit<\/code> to stop the current container application\n<ul>\n<li>If you were connected to the entrypoint application, the container will stop<\/li>\n<li>If you were connected to another shell session, the container will continue<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">[root@controller \/]# docker run -it busybox\r\nUnable to find image 'busybox:latest' locally\r\nlatest: Pulling from library\/busybox\r\n9ad63333ebc9: Pull complete\r\nDigest: sha256:6d9ac9237a84afe1516540f40a0fafdc86859b2141954b4d643af7066d598b74\r\nStatus: Downloaded newer image for busybox:latest\r\n\/ # ps\r\nPID   USER     TIME  COMMAND\r\n    1 root      0:00 sh\r\n    7 root      0:00 ps\r\n\/ # ps aux\r\nPID   USER     TIME  COMMAND\r\n    1 root      0:00 sh\r\n    8 root      0:00 ps aux\r\n\/ # exit\r\n[root@controller \/]# docker ps\r\nCONTAINER ID   IMAGE     COMMAND              CREATED          STATUS          PORTS                                   NAMES\r\n132a8601bc20   httpd     \"httpd-foreground\"   11 minutes ago   Up 11 minutes   0.0.0.0:8080-&gt;80\/tcp, :::8080-&gt;80\/tcp   myapache\r\n\r\n[root@controller \/]# docker ps -a\r\nCONTAINER ID   IMAGE         COMMAND              CREATED              STATUS                         PORTS                                   NAMES\r\n9107d90d8447   busybox       \"sh\"                 About a minute ago   Exited (0) 10 seconds ago                                              youthful_chandrasekhar\r\n132a8601bc20   httpd         \"httpd-foreground\"   11 minutes ago       Up 11 minutes                  0.0.0.0:8080-&gt;80\/tcp, :::8080-&gt;80\/tcp   myapache\r\n605cd349b37c   hello-world   \"\/hello\"             About an hour ago    Exited (0) About an hour ago                                           nervous_keldysh\r\n0d6983933a50   hello-world   \"\/hello\"             12 hours ago         Exited (0) 12 hours ago                                                serene_curie\r\n\r\n[root@controller \/]# docker run -it busybox\r\n\/ # &lt;ctrl+p&gt;&lt;ctrl+q&gt;\r\n\r\n[root@controller \/]# docker ps\r\nCONTAINER ID   IMAGE     COMMAND              CREATED          STATUS          PORTS                                   NAMES\r\na96d522c5b20   busybox   \"sh\"                 45 seconds ago   Up 44 seconds                                           cool_pasteur\r\n132a8601bc20   httpd     \"httpd-foreground\"   12 minutes ago   Up 12 minutes   0.0.0.0:8080-&gt;80\/tcp, :::8080-&gt;80\/tcp   myapache\r\n\r\n[root@controller \/]# docker exec -it myapache sh\r\n\r\n# ps aux\r\nsh: 1: ps: not found\r\n\r\n# ls \/proc\r\n1   acpi       cpuinfo    execdomains  ioports    kmsg         mdstat   net           self      sysrq-trigger  version\r\n10  buddyinfo  crypto     fb           irq        kpagecgroup  meminfo  pagetypeinfo  slabinfo  sysvipc        vmallocinfo\r\n8   bus        devices    filesystems  kallsyms   kpagecount   misc     partitions    softirqs  thread-self    vmstat\r\n9   cgroups    diskstats  fs           kcore      kpageflags   modules  sched_debug   stat      timer_list     xen\r\n92  cmdline    dma        interrupts   key-users  loadavg      mounts   schedstat     swaps     tty            zoneinfo\r\n98  consoles   driver     iomem        keys       locks        mtrr     scsi          sys       uptime\r\n\r\n# cat \/proc\/1\/cmdline\r\nhttpd-DFOREGROUND\r\n# exit\r\n\r\n[root@controller \/]# docker ps\r\nCONTAINER ID   IMAGE     COMMAND              CREATED          STATUS          PORTS                                   NAMES\r\na96d522c5b20   busybox   \"sh\"                 3 minutes ago    Up 3 minutes                                            cool_pasteur\r\n132a8601bc20   httpd     \"httpd-foreground\"   15 minutes ago   Up 15 minutes   0.0.0.0:8080-&gt;80\/tcp, :::8080-&gt;80\/tcp   myapache\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Managing Containers &#8211; Common Commands<br \/>\n<\/span><\/p>\n<ul>\n<li><code>docker ps [-a]<\/code>: shows currently [and past] running containers<\/li>\n<li><code>docker start<\/code>: starts a container from a locally stored image<\/li>\n<li><code>docker stop<\/code>: stops a container using Linux SIGTERM<\/li>\n<li><code>docker restart<\/code>: restarts a currently running container<\/li>\n<li><code>docker kill<\/code>: stops a container using Linux SIGKILL<\/li>\n<li><code>docker rm<\/code>: removes all container files from the host operating system<\/li>\n<\/ul>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Inspecting Container Settings<\/span><\/p>\n<ul>\n<li><code>docker ps<\/code> will show the IDs of containers: pick one!<\/li>\n<li><code>docker inspect &lt;ID&gt; | less<\/code><\/li>\n<li><code>docker inspect --format='{{.NetworkSettings.IPAddress}}' containername<\/code><\/li>\n<li><code>docker inspect --format ='{{.State.Pid}}' containername<\/code><\/li>\n<li>Alternatively, use <code>ps aux<\/code> on the host to find the container PID<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">[root@controller \/]# docker ps -a\r\nCONTAINER ID   IMAGE         COMMAND              CREATED          STATUS                      PORTS                                   NAMES\r\na96d522c5b20   busybox       \"sh\"                 33 minutes ago   Up 33 minutes                                                       cool_pasteur\r\n9107d90d8447   busybox       \"sh\"                 35 minutes ago   Exited (0) 34 minutes ago                                           youthful_chandrasekhar\r\n132a8601bc20   httpd         \"httpd-foreground\"   45 minutes ago   Up 45 minutes               0.0.0.0:8080-&gt;80\/tcp, :::8080-&gt;80\/tcp   myapache\r\n605cd349b37c   hello-world   \"\/hello\"             2 hours ago      Exited (0) 2 hours ago                                              nervous_keldysh\r\n0d6983933a50   hello-world   \"\/hello\"             13 hours ago     Exited (0) 13 hours ago                                             serene_curie\r\n\r\n[root@controller \/]# docker inspect youthful_chandrasekhar | more\r\n[\r\n    {\r\n        \"Id\": \"9107d90d8447d0f70238eb121660e4db746048d37d3294dd3ec0e8215006752b\",\r\n        \"Created\": \"2024-02-20T10:02:35.922550351Z\",\r\n        \"Path\": \"sh\",\r\n        \"Args\": [],\r\n        \"State\": {\r\n            \"Status\": \"exited\",\r\n            \"Running\": false,\r\n            \"Paused\": false,\r\n            \"Restarting\": false,\r\n            \"OOMKilled\": false,\r\n            \"Dead\": false,\r\n            \"Pid\": 0,\r\n            \"ExitCode\": 0,\r\n            \"Error\": \"\",\r\n            \"StartedAt\": \"2024-02-20T10:02:36.401131212Z\",\r\n            \"FinishedAt\": \"2024-02-20T10:04:14.878553209Z\"\r\n        },\r\n...\r\n[root@controller \/]# docker ps\r\nCONTAINER ID   IMAGE     COMMAND              CREATED          STATUS          PORTS                                   NAMES\r\na96d522c5b20   busybox   \"sh\"                 33 minutes ago   Up 33 minutes                                           cool_pasteur\r\n132a8601bc20   httpd     \"httpd-foreground\"   45 minutes ago   Up 45 minutes   0.0.0.0:8080-&gt;80\/tcp, :::8080-&gt;80\/tcp   myapache\r\n\r\n[root@controller \/]# docker inspect cool_pasteur | more\r\n[\r\n    {\r\n        \"Id\": \"a96d522c5b2095c33aa647f52807727831b161815937f0500941e685f22f8a00\",\r\n        \"Created\": \"2024-02-20T10:05:07.9709231Z\",\r\n        \"Path\": \"sh\",\r\n        \"Args\": [],\r\n        \"State\": {\r\n            \"Status\": \"running\",\r\n            \"Running\": true,\r\n            \"Paused\": false,\r\n            \"Restarting\": false,\r\n            \"OOMKilled\": false,\r\n            \"Dead\": false,\r\n            \"Pid\": 349943,\r\n            \"ExitCode\": 0,\r\n            \"Error\": \"\",\r\n            \"StartedAt\": \"2024-02-20T10:05:08.410217942Z\",\r\n            \"FinishedAt\": \"0001-01-01T00:00:00Z\"\r\n        },\r\n        \"Image\": \"sha256:3f57d9401f8d42f986df300f0c69192fc41da28ccc8d797829467780db3dd741\",\r\n        \"ResolvConfPath\": \"\/var\/lib\/docker\/containers\/a96d522c5b2095c33aa647f52807727831b161815937f0500941e685f22f8a00\/resolv.conf\",\r\n        \"HostnamePath\": \"\/var\/lib\/docker\/containers\/a96d522c5b2095c33aa647f52807727831b161815937f0500941e685f22f8a00\/hostname\",\r\n        \"HostsPath\": \"\/var\/lib\/docker\/containers\/a96d522c5b2095c33aa647f52807727831b161815937f0500941e685f22f8a00\/hosts\",\r\n        \"LogPath\": \"\/var\/lib\/docker\/containers\/a96d522c5b2095c33aa647f52807727831b161815937f0500941e685f22f8a00\/a96d522c5b2095c33aa647f52807727831b161815937f0500941e685f22f8a00-json.l\r\nog\",\r\n...\r\n[root@controller \/]# docker inspect --format='{{.NetworkSettings.IPAddress}}' cool_pasteur\r\n172.17.0.3\r\n\r\n[root@controller \/]# docker inspect --format ='{{.State.Pid}}' cool_pasteur\r\n=349943\r\n\r\n[root@controller \/]# ps fax | more\r\n    PID TTY      STAT   TIME COMMAND\r\n      2 ?        S      0:00 [kthreadd]\r\n      3 ?        I&lt;     0:00  \\_ [rcu_gp]\r\n      4 ?        I&lt;     0:00  \\_ [rcu_par_gp]\r\n      5 ?        I&lt;     0:00  \\_ [slub_flushwq]\r\n      7 ?        I&lt;     0:00  \\_ [kworker\/0:0H-events_highpri]\r\n     10 ?        I&lt;     0:00  \\_ [mm_percpu_wq]\r\n     11 ?        S      0:00  \\_ [rcu_tasks_rude_]\r\n     12 ?        S      0:00  \\_ [rcu_tasks_trace]\r\n     13 ?        S      0:00  \\_ [ksoftirqd\/0]\r\n     14 ?        I      0:51  \\_ [rcu_sched]\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Managing Images<\/span><\/p>\n<ul>\n<li>After fetching, the container images are stored on the host<\/li>\n<li>Use <code>docker images<\/code> to get a list of images<\/li>\n<li>Or use <code>docker image --help<\/code> to get an overview of all options related to managing container images<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true \">[root@controller \/]# docker images\r\nREPOSITORY    TAG       IMAGE ID       CREATED        SIZE\r\nbusybox       latest    3f57d9401f8d   4 weeks ago    4.26MB\r\nhttpd         latest    2776f4da9d55   4 weeks ago    167MB\r\nhello-world   latest    d2c94e258dcb   9 months ago   13.3kB\r\n[root@controller \/]# docker image\r\nUsage:  docker image COMMAND\r\nManage images\r\nCommands:\r\n  build       Build an image from a Dockerfile\r\n  history     Show the history of an image\r\n  import      Import the contents from a tarball to create a filesystem image\r\n  inspect     Display detailed information on one or more images\r\n  load        Load an image from a tar archive or STDIN\r\n  ls          List images\r\n  prune       Remove unused images\r\n  pull        Download an image from a registry\r\n  push        Upload an image to a registry\r\n  rm          Remove one or more images\r\n  save        Save one or more images to a tar archive (streamed to STDOUT by default)\r\n  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE\r\n\r\n[root@controller \/]# docker image ls\r\nREPOSITORY    TAG       IMAGE ID       CREATED        SIZE\r\nbusybox       latest    3f57d9401f8d   4 weeks ago    4.26MB\r\nhttpd         latest    2776f4da9d55   4 weeks ago    167MB\r\nhello-world   latest    d2c94e258dcb   9 months ago   13.3kB\r\n\r\n[root@controller \/]# docker image inspect 3f57d9401f8d | more\r\n[\r\n    {\r\n        \"Id\": \"sha256:3f57d9401f8d42f986df300f0c69192fc41da28ccc8d797829467780db3dd741\",\r\n        \"RepoTags\": [\r\n            \"busybox:latest\"\r\n        ],\r\n        \"RepoDigests\": [\r\n            \"busybox@sha256:6d9ac9237a84afe1516540f40a0fafdc86859b2141954b4d643af7066d598b74\"\r\n        ],\r\n        \"Parent\": \"\",\r\n        \"Comment\": \"buildkit.dockerfile.v0\",\r\n        \"Created\": \"2024-01-17T21:49:12Z\",\r\n        \"Container\": \"\",\r\n        \"ContainerConfig\": {\r\n            \"Hostname\": \"\",\r\n            \"Domainname\": \"\",\r\n...\r\n[root@controller \/]# docker image ls\r\nREPOSITORY    TAG       IMAGE ID       CREATED        SIZE\r\nbusybox       latest    3f57d9401f8d   4 weeks ago    4.26MB\r\nhttpd         latest    2776f4da9d55   4 weeks ago    167MB\r\nhello-world   latest    d2c94e258dcb   9 months ago   13.3kB\r\n\r\n[root@controller \/]# docker image rm d2c94e258dcb\r\nError response from daemon: conflict: unable to delete d2c94e258dcb (must be forced) - image is being used by stopped container 0d6983933a50\r\n\r\n[root@controller \/]# docker image rm -f d2c94e258dcb\r\nUntagged: hello-world:latest\r\nUntagged: hello-world@sha256:d000bc569937abbe195e20322a0bde6b2922d805332fd6d8a68b19f524b7d21d\r\nDeleted: sha256:d2c94e258dcb3c5ac2798d32e1249e42ef01cba4841c2234249495f87264ac5a\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Container Logging<\/span><\/p>\n<ul>\n<li>The container application does not connect to a STDOUT, which is why logs,<br \/>\nby default, are written to the container<\/li>\n<li>Use <code>docker logs mycontainer<\/code> to get access to the container log<\/li>\n<li>Using <code>docker logs<\/code> is convenient for troubleshooting<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true\">[root@controller \/]# docker run mariadb\r\nUnable to find image 'mariadb:latest' locally\r\nlatest: Pulling from library\/mariadb\r\n01007420e9b0: Pull complete\r\n0afd642f34d1: Pull complete\r\n696ca6335161: Pull complete\r\na7e0c48ca7d7: Pull complete\r\n8d9e67098d76: Pull complete\r\n72f5e793adab: Pull complete\r\nd5f886ae8a97: Pull complete\r\n7e77db7838e8: Pull complete\r\nDigest: sha256:55d9608d84658cbc691f52cd6389386a15e6c671cb5708b9f3af5782af3b4dbb\r\nStatus: Downloaded newer image for mariadb:latest\r\n2024-02-20 11:21:20+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.2.3+maria~ubu2204 started.\r\n2024-02-20 11:21:21+00:00 [Warn] [Entrypoint]: \/sys\/fs\/cgroup\/pids:\/docker\/e8628333ea4940fdcf8352e04b7106be21d9c65c023013f05d52f46ee5b5378a\r\n11:cpu,cpuacct:\/docker\/e8628333ea4940fdcf8352e04b7106be21d9c65c023013f05d52f46ee5b5378a\r\n10:rdma:\/docker\/e8628333ea4940fdcf8352e04b7106be21d9c65c023013f05d52f46ee5b5378a\r\n9:blkio:\/docker\/e8628333ea4940fdcf8352e04b7106be21d9c65c023013f05d52f46ee5b5378a\r\n8:memory:\/docker\/e8628333ea4940fdcf8352e04b7106be21d9c65c023013f05d52f46ee5b5378a\r\n7:hugetlb:\/docker\/e8628333ea4940fdcf8352e04b7106be21d9c65c023013f05d52f46ee5b5378a\r\n6:net_cls,net_prio:\/docker\/e8628333ea4940fdcf8352e04b7106be21d9c65c023013f05d52f46ee5b5378a\r\n5:perf_event:\/docker\/e8628333ea4940fdcf8352e04b7106be21d9c65c023013f05d52f46ee5b5378a\r\n4:freezer:\/docker\/e8628333ea4940fdcf8352e04b7106be21d9c65c023013f05d52f46ee5b5378a\r\n3:devices:\/docker\/e8628333ea4940fdcf8352e04b7106be21d9c65c023013f05d52f46ee5b5378a\r\n2:cpuset:\/docker\/e8628333ea4940fdcf8352e04b7106be21d9c65c023013f05d52f46ee5b5378a\r\n1:name=systemd:\/docker\/e8628333ea4940fdcf8352e04b7106be21d9c65c023013f05d52f46ee5b5378a\r\n0::\/\/memory.pressure not writable, functionality unavailable to MariaDB\r\n2024-02-20 11:21:21+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'\r\n2024-02-20 11:21:21+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.2.3+maria~ubu2204 started.\r\n2024-02-20 11:21:21+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified\r\n        You need to specify one of MARIADB_ROOT_PASSWORD, MARIADB_ROOT_PASSWORD_HASH, MARIADB_ALLOW_EMPTY_ROOT_PASSWORD and MARIADB_RANDOM_ROOT_PASSWORD\r\n\r\n[root@controller \/]# docker run -d mariadb\r\n3429b13ec1e95890be2f06714d1a688785be7154453c5f78ef0cca68e995098f\r\n\r\n[root@controller \/]# docker ps\r\nCONTAINER ID   IMAGE     COMMAND              CREATED             STATUS             PORTS                                   NAMES\r\na96d522c5b20   busybox   \"sh\"                 About an hour ago   Up About an hour                                           cool_pasteur\r\n132a8601bc20   httpd     \"httpd-foreground\"   About an hour ago   Up About an hour   0.0.0.0:8080-&gt;80\/tcp, :::8080-&gt;80\/tcp   myapache\r\n\r\n[root@controller \/]# docker ps -a\r\nCONTAINER ID   IMAGE          COMMAND                  CREATED             STATUS                         PORTS                                   NAMES\r\n3429b13ec1e9   mariadb        \"docker-entrypoint.s\u2026\"   17 seconds ago      Exited (1) 14 seconds ago                                              trusting_rosalind\r\ne8628333ea49   mariadb        \"docker-entrypoint.s\u2026\"   54 seconds ago      Exited (1) 48 seconds ago                                              sharp_kowalevski\r\na96d522c5b20   busybox        \"sh\"                     About an hour ago   Up About an hour                                                       cool_pasteur\r\n9107d90d8447   busybox        \"sh\"                     About an hour ago   Exited (0) About an hour ago                                           youthful_chandrasekhar\r\n132a8601bc20   httpd          \"httpd-foreground\"       About an hour ago   Up About an hour               0.0.0.0:8080-&gt;80\/tcp, :::8080-&gt;80\/tcp   myapache\r\n605cd349b37c   d2c94e258dcb   \"\/hello\"                 3 hours ago         Exited (0) 3 hours ago                                                 nervous_keldysh\r\n0d6983933a50   d2c94e258dcb   \"\/hello\"                 14 hours ago        Exited (0) 14 hours ago                                                serene_curie\r\n\r\n[root@controller \/]# docker logs trusting_rosalind\r\n2024-02-20 11:21:54+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.2.3+maria~ubu2204 started.\r\n2024-02-20 11:21:55+00:00 [Warn] [Entrypoint]: \/sys\/fs\/cgroup\/pids:\/docker\/3429b13ec1e95890be2f06714d1a688785be7154453c5f78ef0cca68e995098f\r\n11:cpu,cpuacct:\/docker\/3429b13ec1e95890be2f06714d1a688785be7154453c5f78ef0cca68e995098f\r\n10:rdma:\/docker\/3429b13ec1e95890be2f06714d1a688785be7154453c5f78ef0cca68e995098f\r\n9:blkio:\/docker\/3429b13ec1e95890be2f06714d1a688785be7154453c5f78ef0cca68e995098f\r\n8:memory:\/docker\/3429b13ec1e95890be2f06714d1a688785be7154453c5f78ef0cca68e995098f\r\n7:hugetlb:\/docker\/3429b13ec1e95890be2f06714d1a688785be7154453c5f78ef0cca68e995098f\r\n6:net_cls,net_prio:\/docker\/3429b13ec1e95890be2f06714d1a688785be7154453c5f78ef0cca68e995098f\r\n5:perf_event:\/docker\/3429b13ec1e95890be2f06714d1a688785be7154453c5f78ef0cca68e995098f\r\n4:freezer:\/docker\/3429b13ec1e95890be2f06714d1a688785be7154453c5f78ef0cca68e995098f\r\n3:devices:\/docker\/3429b13ec1e95890be2f06714d1a688785be7154453c5f78ef0cca68e995098f\r\n2:cpuset:\/docker\/3429b13ec1e95890be2f06714d1a688785be7154453c5f78ef0cca68e995098f\r\n1:name=systemd:\/docker\/3429b13ec1e95890be2f06714d1a688785be7154453c5f78ef0cca68e995098f\r\n0::\/\/memory.pressure not writable, functionality unavailable to MariaDB\r\n2024-02-20 11:21:55+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'\r\n2024-02-20 11:21:55+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.2.3+maria~ubu2204 started.\r\n2024-02-20 11:21:55+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified\r\n        You need to specify one of MARIADB_ROOT_PASSWORD, MARIADB_ROOT_PASSWORD_HASH, MARIADB_ALLOW_EMPTY_ROOT_PASSWORD and MARIADB_RANDOM_ROOT_PASSWORD\r\n\r\n[root@controller \/]# docker run -d --name mydb mariadb -e MYSQL_ROOT_PASSWORD=password\r\n2024-02-20 11:25:50+00:00 [Note] [Entrypoint]: Entrypoint script for MariaDB Server 1:11.2.3+maria~ubu2204 started.\r\n2024-02-20 11:25:50+00:00 [ERROR] [Entrypoint]: mariadbd failed while attempting to check config\r\n        command was: mariadbd -e MYSQL_ROOT_PASSWORD=password --verbose --help\r\n        2024-02-20 11:25:50 0 [Warning] Could not open mysql.plugin table: \"Table 'mysql.plugin' doesn't exist\". Some options may be missing from the help text\r\n2024-02-20 11:25:50 0 [ERROR] mariadbd: unknown option '-e'\r\n\r\n[root@controller \/]# docker run -d --name mydb -e MYSQL_ROOT_PASSWORD=password mariadb\r\ndocker: Error response from daemon: Conflict. The container name \"\/mydb\" is already in use by container \"25dfb9b7e1104550fc60ac7f556fb654637ef3457c3be31ae7c148ccb3c4239a\". You have to remove (or rename) that container to be able to reuse that name.\r\nSee 'docker run --help'.\r\n\r\n[root@controller \/]# docker rm mydb\r\nmydb\r\n[root@controller \/]# docker run -d --name mydb -e MYSQL_ROOT_PASSWORD=password mariadb\r\na229ccfd0f818f06b641ca38350e49cb7528732915166c0baeaec16d204cb9bf\r\n\r\n[root@controller \/]# docker ps\r\nCONTAINER ID   IMAGE     COMMAND                  CREATED             STATUS             PORTS                                   NAMES\r\na229ccfd0f81   mariadb   \"docker-entrypoint.s\u2026\"   33 seconds ago      Up 31 seconds      3306\/tcp                                mydb\r\na96d522c5b20   busybox   \"sh\"                     About an hour ago   Up About an hour                                           cool_pasteur\r\n132a8601bc20   httpd     \"httpd-foreground\"       2 hours ago         Up 2 hours         0.0.0.0:8080-&gt;80\/tcp, :::8080-&gt;80\/tcp   myapache\r\n\r\n<\/pre>\n<p>&nbsp;<\/p>\n<p><span style=\"color: #3366ff\">Lab: Using Containers<\/span><\/p>\n<ul>\n<li>Run the latest version of Ubuntu in a container<\/li>\n<li>In interactive mode, start a bash shell and explore the<code> \/etc\/os-release<\/code> file, as well as the kernel version (<code>uname -r<\/code>)<\/li>\n<li>Disconnect from the container without shutting it down<\/li>\n<\/ul>\n<pre class=\"lang:default decode:true \">[root@controller \/]# docker run -it ubuntu:latest\r\nUnable to find image 'ubuntu:latest' locally\r\nlatest: Pulling from library\/ubuntu\r\n01007420e9b0: Already exists\r\nDigest: sha256:f9d633ff6640178c2d0525017174a688e2c1aef28f0a0130b26bd5554491f0da\r\nStatus: Downloaded newer image for ubuntu:latest\r\n\r\nroot@cc94dcd26493:\/# cat \/etc\/os-release\r\nPRETTY_NAME=\"Ubuntu 22.04.3 LTS\"\r\nNAME=\"Ubuntu\"\r\nVERSION_ID=\"22.04\"\r\nVERSION=\"22.04.3 LTS (Jammy Jellyfish)\"\r\nVERSION_CODENAME=jammy\r\nID=ubuntu\r\nID_LIKE=debian\r\nHOME_URL=\"https:\/\/www.ubuntu.com\/\"\r\nSUPPORT_URL=\"https:\/\/help.ubuntu.com\/\"\r\nBUG_REPORT_URL=\"https:\/\/bugs.launchpad.net\/ubuntu\/\"\r\nPRIVACY_POLICY_URL=\"https:\/\/www.ubuntu.com\/legal\/terms-and-policies\/privacy-policy\"\r\nUBUNTU_CODENAME=jammy\r\n\r\nroot@cc94dcd26493:\/# uname -r\r\n4.18.0-500.el8.x86_64\r\n\r\nroot@cc94dcd26493:\/# &lt;ctrl+p&gt;&lt;ctrl+q&gt;\r\n[root@controller \/]#\r\n\r\n[root@controller \/]# uname -r\r\n4.18.0-500.el8.x86_64\r\n\r\n[root@controller \/]# docker ps\r\nCONTAINER ID   IMAGE           COMMAND                  CREATED              STATUS              PORTS                                   NAMES\r\ncc94dcd26493   ubuntu:latest   \"\/bin\/bash\"              About a minute ago   Up About a minute                                           sweet_mclean\r\na229ccfd0f81   mariadb         \"docker-entrypoint.s\u2026\"   6 minutes ago        Up 6 minutes        3306\/tcp                                mydb\r\na96d522c5b20   busybox         \"sh\"                     2 hours ago          Up 2 hours                                                  cool_pasteur\r\n132a8601bc20   httpd           \"httpd-foreground\"       2 hours ago          Up 2 hours          0.0.0.0:8080-&gt;80\/tcp, :::8080-&gt;80\/tcp   myapac<\/pre>\n<p>As we see the kernel version in the container is alwys the same like in the virtual machine.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[92],"tags":[],"_links":{"self":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/5533"}],"collection":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/comments?post=5533"}],"version-history":[{"count":32,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/5533\/revisions"}],"predecessor-version":[{"id":5565,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/posts\/5533\/revisions\/5565"}],"wp:attachment":[{"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/media?parent=5533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/categories?post=5533"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/miro.borodziuk.eu\/index.php\/wp-json\/wp\/v2\/tags?post=5533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}