How to launch Apache webserver using Docker file on Ubuntu 21.04
To Launch Apache webserver using Docker file on Ubuntu 21.04
Introduction:
Docker is a collection of the platform as service products that deliver software packages in containers. Each container separates itself from the others, and it comes with its own software, libraries, and configuration files.
Step 1: Check the OS version by using below command
root@linuxhelp:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 21.04
Release: 21.04
Codename: hirsute
Step 2: Check the presence of Docker package by using 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/bionic,now 5:20.10.12~3-0~ubuntu-bionic amd64 [installed,automatic]
docker-ce-rootless-extras/bionic,now 5:20.10.12~3-0~ubuntu-bionic amd64 [installed,automatic]
docker-ce/bionic,now 5:20.10.12~3-0~ubuntu-bionic amd64 [installed]
docker-scan-plugin/bionic,now 0.12.0~ubuntu-bionic amd64 [installed,automatic]
Step 3: List the Docker images by using below command
root@linuxhelp:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest d13c942271d6 3 days ago 72.8MB
Step 4: Create a Docker File by using below command
root@linuxhelp:~# vi dockerfiles/dockerfile
# Getting image from Local
FROM ubuntu
ARG DEBIAN_FRONTEND=noninteractive
RUN apt-get update
RUN apt-get -y install apache2
RUN apt-get update
RUN apt-get -y install apache2-utils
RUN apt install -y tcl
EXPOSE 80
ENTRYPOINT ["apache2ctl"]
CMD ["-DFOREGROUND"]
Step 5: Build the Docker image by using Docker file
root@linuxhelp:~# docker build -t webserver dockerfiles/.
Sending build context to Docker daemon 2.048kB
Step 1/10 : FROM ubuntu
---> d13c942271d6
Step 2/10 : ARG DEBIAN_FRONTEND=noninteractive
---> Running in d134895cc662
Removing intermediate container d134895cc662
---> ba9ef23e4a42
Step 3/10 : RUN apt-get update
---> Running in e1f1e5de2c8d
Get:1 http://archive.ubuntu.com/ubuntu focal InRelease [265 kB]
Get:2 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:3 http://archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:4 http://archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:5 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [1408 kB]
Get:6 http://archive.ubuntu.com/ubuntu focal/multiverse amd64 Packages [177 kB]
Get:7 http://archive.ubuntu.com/ubuntu focal/main amd64 Packages [1275 kB]
Get:8 http://security.ubuntu.com/ubuntu focal-security/restricted amd64 Packages [821 kB]
Get:9 http://archive.ubuntu.com/ubuntu focal/restricted amd64 Packages [33.4 kB]
Get:10 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 Packages [30.1 kB]
ibtcl8.6:amd64 (8.6.10+dfsg-1) ...
Selecting previously unselected package tcl8.6.
Preparing to unpack .../tcl8.6_8.6.10+dfsg-1_amd64.deb ...
Unpacking tcl8.6 (8.6.10+dfsg-1) ...
Selecting previously unselected package tcl.
Preparing to unpack .../archives/tcl_8.6.9+1_amd64.deb ...
Unpacking tcl (8.6.9+1) ...
Setting up libtcl8.6:amd64 (8.6.10+dfsg-1) ...
Setting up tcl8.6 (8.6.10+dfsg-1) ...
Setting up tcl (8.6.9+1) ...
Processing triggers for libc-bin (2.31-0ubuntu9.2) ...
Removing intermediate container 45701703a2e1
---> 8c51d8fe77f0
Step 8/10 : EXPOSE 80
---> Running in 7e60ad0783f1
Removing intermediate container 7e60ad0783f1
---> 86caed02d522
Step 9/10 : ENTRYPOINT ["apache2ctl"]
---> Running in 1b8ab835277c
Removing intermediate container 1b8ab835277c
---> 399a936984ff
Step 10/10 : CMD ["-DFOREGROUND"]
---> Running in bac82e5ae550
Removing intermediate container bac82e5ae550
---> e9bceb190302
Successfully built e9bceb190302
Successfully tagged webserver:latest
Step 6: List the Docker images by using below command
root@linuxhelp:~# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
webserver latest e9bceb190302 37 seconds ago 225MB
ubuntu latest d13c942271d6 3 days ago 72.8MB
Step 7: Run the Docker container by using the below command
root@linuxhelp:~# docker run -itd webserver
b35305a031ecde31731022fb8dabbedafc0f279114e655b03a7bfbbd9c59d9d1
Step 8: View the process status of the container by using below command
root@linuxhelp:~# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b35305a031ec webserver "apache2ctl -DFOREGR…" 13 seconds ago Up 12 seconds 80/tcp vigorous_cerf
Step 9: Check the IP address of the container by using below command
root@linuxhelp:~# docker inspect vigorous_cerf | grep IP
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"IPAMConfig": null,
"IPAddress": "172.17.0.2",
"IPPrefixLen": 16,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
Step 10: Ping the IP address in browser by using below command
By this to launch Apache webserver using Docker file on Ubuntu 21.04 have been completed