How to build Docker Image using Docker Files on Rocky Linux 9.2
To build Docker Image using Docker Files on Rocky Linux 9.2
Introduction
A Docker image is an unchanging file that contains source code, libraries, dependencies, tools, and other files necessary to run a program.
Procedure
Step 1: Check the OS version by using the following command
[root@Linuxhelp /]# cat /etc/os-release
NAME="Rocky Linux"
VERSION="9.2 (Blue Onyx)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="9.2"
PLATFORM_ID="platform:el9"
PRETTY_NAME="Rocky Linux 9.2 (Blue Onyx)"
ANSI_COLOR="0;32"
LOGO="fedora-logo-icon"
CPE_NAME="cpe:/o:rocky:rocky:9::baseos"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
SUPPORT_END="2032-05-31"
ROCKY_SUPPORT_PRODUCT="Rocky-Linux-9"
ROCKY_SUPPORT_PRODUCT_VERSION="9.2"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="9.2"
Step 2: check the status of the docker by using the following command.
[root@Linuxhelp /]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; preset: disabled)
Active: active (running) since Sun 2023-08-20 06:09:53 IST; 15min ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 7491 (dockerd)
Tasks: 12
Memory: 35.5M
CPU: 872ms
CGroup: /system.slice/docker.service
└─7491 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Aug 20 06:09:53 Linuxhelp dockerd[7491]: time="2023-08-20T06:09:53.370561076+05:30" level=info msg="Firewalld: >
Aug 20 06:09:53 Linuxhelp dockerd[7491]: time="2023-08-20T06:09:53.627223628+05:30" level=info msg="Loading con>
Aug 20 06:09:53 Linuxhelp dockerd[7491]: time="2023-08-20T06:09:53.662696519+05:30" level=info msg="Docker daem>
Aug 20 06:09:53 Linuxhelp dockerd[7491]: time="2023-08-20T06:09:53.663091996+05:30" level=info msg="Daemon has >
Aug 20 06:09:53 Linuxhelp dockerd[7491]: time="2023-08-20T06:09:53.715368378+05:30" level=info msg="API listen >
Aug 20 06:09:53 Linuxhelp systemd[1]: Started Docker Application Container Engine.
Aug 20 06:16:59 Linuxhelp dockerd[7491]: time="2023-08-20T06:16:59.158884242+05:30" level=warning msg="no trace>
Aug 20 06:20:12 Linuxhelp dockerd[7491]: time="2023-08-20T06:20:12.290977852+05:30" level=warning msg="no trace>
Aug 20 06:20:16 Linuxhelp dockerd[7491]: 2023/08/20 06:20:16 http2: server: error reading preface from client @>
Aug 20 06:20:16 Linuxhelp dockerd[7491]: time="2023-08-20T06:20:16.939653168+05:30" level=warning msg="no trace>
Step 3: Create the directory named as dockerfiles by using the following command.
[root@Linuxhelp /]# mkdir /dockerfiles
Step 4: Inside the dockerfiles directory, create a file named dockerfile using a text editor and insert the below lines.Then save and exit from the file using :wq! command
[root@Linuxhelp /]# vim /dockerfiles/dockerfile
Step 5: Run the docker build command by using the following command
[root@Linuxhelp /]# docker build /dockerfiles/
[+] Building 24.9s (6/6) FINISHED docker:default
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [internal] load build definition from dockerfile 0.1s
=> => transferring dockerfile: 196B 0.0s
=> [internal] load metadata for docker.io/library/httpd:latest 4.3s
=> [1/2] FROM docker.io/library/httpd@sha256:333f7bca9fb72248f301fd2ae4892b86d36cc2fdf4c6aa49a6700f27c8 13.8s
=> => resolve docker.io/library/httpd@sha256:333f7bca9fb72248f301fd2ae4892b86d36cc2fdf4c6aa49a6700f27c8e 0.0s
=> => sha256:333f7bca9fb72248f301fd2ae4892b86d36cc2fdf4c6aa49a6700f27c8e06daf 1.86kB / 1.86kB 0.0s
=> => sha256:18427eed921af003c951b5c97f0bde8a6df40cc7cb09b9739b9e35041a3c3acd 1.37kB / 1.37kB 0.0s
=> => sha256:76e5ad98b58ec86acd1e38d6ff79761144292113cecee2087b8827c12a5fd0b5 9.38kB / 9.38kB 0.0s
=> => sha256:52d2b7f179e32b4cbd579ee3c4958027988f9a8274850ab0c7c24661e3adaac5 29.12MB / 29.12MB 4.0s
=> => sha256:5bfaffbad7bfdb3a190a47edc6bd90202070f99d08c7a3f5e4461b18b328b19a 177B / 177B 0.4s
=> => sha256:460cd5c32012ea426753b5b04327912c7b9d7c11de17a9f11590af67f48a2eee 4.19MB / 4.19MB 1.5s
=> => sha256:ba29f61f6139e909652f665787ba3ba84439231e6b468bf49b21fb0f62d6d0ab 31.36MB / 31.36MB 6.1s
=> => sha256:92baf798eff79e50d2460a1b4791a070c9550e497dbbbd0a832dfe293f39d383 296B / 296B 1.8s
=> => extracting sha256:52d2b7f179e32b4cbd579ee3c4958027988f9a8274850ab0c7c24661e3adaac5 5.0s
=> => extracting sha256:5bfaffbad7bfdb3a190a47edc6bd90202070f99d08c7a3f5e4461b18b328b19a 0.0s
=> => extracting sha256:460cd5c32012ea426753b5b04327912c7b9d7c11de17a9f11590af67f48a2eee 0.5s
=> => extracting sha256:ba29f61f6139e909652f665787ba3ba84439231e6b468bf49b21fb0f62d6d0ab 3.6s
=> => extracting sha256:92baf798eff79e50d2460a1b4791a070c9550e497dbbbd0a832dfe293f39d383 0.0s
=> [2/2] RUN apt-get update 6.2s
=> exporting to image 0.4s
=> => exporting layers 0.4s
=> => writing image sha256:ea9fe435bd182c0e511c99ac05ee2d95ebfd6d84de2ca18b508f47868c998213 0.0s
Step 6: Check the docker image by using the following command
[root@Linuxhelp /]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> ea9fe435bd18 12 seconds ago 187MB
Step 7: Run the docker images by using the IMAGE ID
[root@Linuxhelp /]# docker run ea9fe435bd18
Welcome to Linuxhelp.com
This is the message which we printed in the vim /dockerfiles/dockerfile configuration file
Conclusion:
We have reached the end of this article. In this guide, we have walked you through the steps required to build docker image using docker files on Rocky Linux 9.2. Your feedback is much welcome.
These containers are compact, portable units in which you can start up an application quickly and easily