How to Build Docker image using Docker files on Rocky Linux 8.6
To build Docker image using Docker files on Rocky Linux 8.6
Introduction:
A Docker image is an unchanging file that contains source code, libraries, dependencies, tools, and other files necessary to run a program.
Installation Procedure:
Step 1: Check the OS version
[root@linuxhelp ~]# cat /etc/os-release
NAME="Rocky Linux"
VERSION="8.6 (Green Obsidian)"
ID="rocky"
ID_LIKE="rhel centos fedora"
VERSION_ID="8.6"
PLATFORM_ID="platform:el8"
PRETTY_NAME="Rocky Linux 8.6 (Green Obsidian)"
ANSI_COLOR="0;32"
CPE_NAME="cpe:/o:rocky:rocky:8:GA"
HOME_URL="https://rockylinux.org/"
BUG_REPORT_URL="https://bugs.rockylinux.org/"
ROCKY_SUPPORT_PRODUCT="Rocky Linux"
ROCKY_SUPPORT_PRODUCT_VERSION="8"
REDHAT_SUPPORT_PRODUCT="Rocky Linux"
REDHAT_SUPPORT_PRODUCT_VERSION="8"
Step 2: check the status of docker
[root@linuxhelp ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor pre>
Active: active (running) since Fri 2022-07-22 02:35:59 EDT; 2 weeks 2 days a>
Docs: https://docs.docker.com
Main PID: 43049 (dockerd)
Tasks: 9
Memory: 47.0M
CGroup: /system.slice/docker.service
└─43049 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/conta>
Step 3: To create directory for the docker file
[root@linuxhelp ~]# mkdir /dockerfiles
Step 4: To open the configuration file
[root@linuxhelp ~]# vim /dockerfiles/dockerfile
#Getting image from docker hub
FROM httpd
RUN apt-get update
CMD ["echo","Apache web server image"]
Step 5: To run the docker build
[root@linuxhelp ~]# docker build /dockerfiles/
Sending build context to Docker daemon 2.048kB
Step 1/3 : FROM httpd
latest: Pulling from library/httpd
1efc276f4ff9: Pull complete
aed046121ed8: Pull complete
4340e7be3d7f: Pull complete
80e368ef21fc: Pull complete
80cb79a80bbe: Pull complete
Digest: sha256:343452ec820a5d59eb3ab9aaa6201d193f91c3354f8c4f29705796d9353d4cc6
Status: Downloaded newer image for httpd:latest
---> f2a976f932ec
Step 2/3 : RUN apt-get update
---> Running in e55ed9b99dfb
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 [8182 kB]
Get:5 http://deb.debian.org/debian-security bullseye-security/main amd64 Packages [170 kB]
Get:6 http://deb.debian.org/debian bullseye-updates/main amd64 Packages [2592 B]
Fetched 8563 kB in 3s (2584 kB/s)
Reading package lists...
Removing intermediate container e55ed9b99dfb
---> 320678b9ed02
Step 3/3 : CMD ["echo",Apache web server image"]
---> Running in a1f0e21a467e
Removing intermediate container a1f0e21a467e
---> 8ec0e4647349
Successfully built 8ec0e4647349
Step 6: check the docker image
[root@linuxhelp ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> a3cfdca80718 18 seconds ago 163MB
httpd latest f2a976f932ec 5 days ago 145MB
hello-world latest feb5d9fea6a5 10 months ago 13.3kB
Step 7: Run the docker images by using image ID
[root@linuxhelp ~]# docker run a3cfdca80718
Apache web server image
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 8.6. Your feedback is much welcome.
Comments ( 0 )
No comments available