How to build Docker Images using Docker File on Debian 11.3
To Build Docker Images Using Docker File on Debian 11.3.
Introduction:
A Docker image is a file used to execute code in a Docker container. Docker images act as a set of instructions to build a Docker container, like a template. Docker images also act as the starting point when using Docker.
Procedure:
Step 1: Check the OS version by using the below Command
root@linuxhelp: ~# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 11 (bullseye)
Release: 11
Codename: bullseye
Step 2: To verify the Docker image install by using the below command
root@linuxhelp:~# apt list --installed | grep docker
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
docker-ce-cli/bullseye,now 5:20.10.17~3-0~debian-bullseye amd64 [installed]
docker-ce-rootless-extras/bullseye, now 5:20.10.17~3-0~debian-bullseye amd64 [installed,automatic]
docker-ce/bullseye,now 5:20.10.17~3-0~debian-bullseye amd64 [installed]
docker-scan-plugin/bullseye, now 0.17.0~debian-bullseye amd64 [installed,automatic]
Step 3: Check the Docker Version by using the below command
root@linuxhelp: ~# docker -v
Docker version 20.10.17, build 100c701
Step 4: Next create a folder, named docker files by using the below command
root@linuxhelp: ~# mkdir dockerfiles
Step 5: Make a new file name docker files inside the docker folder by using the below command
root@linuxhelp: ~# nano dockerfiles/dockerfile
#Getting Image from docker hub
From httpd
RUN apt-get update
CMD [“echo”, “Apache Web Server Image”]
Step 6: Next build the file and give the location of Docker file by using the below command
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 3d2e57e3330b
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 1s (5837 kB/s)
Reading package lists...
Removing intermediate container 3d2e57e3330b
---> c14b20874022
Step 3/3 : CMD ["echo", "Apache webserver image"]
---> Running in 4890f5ed1eee
Removing intermediate container 4890f5ed1eee
---> 299f66779d73
Successfully built 299f66779d73
Step 7: List the docker images by using the below command
root@linuxhelp: ~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 299f66779d73 25 seconds ago 163MB
<none> <none> f645b68f51bb 32 minutes ago 142MB
httpd latest f2a976f932ec 4 days ago 145MB
debian latest 07d9246c53a6 4 days ago 124MB
hello-world latest feb5d9fea6a5 10 months ago 13.3kB
Step 8: Run the docker images by using the below command
root@linuxhelp: ~# docker run 299f66779d73
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 Images using Docker Files on Debian 11.3. Your feedback is much welcome.