• Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • Categories
    Category
    {{ postCtrl.tags }}
    • {{ category.tag_type }}

      • {{tag.tag_name}}
      • View more
  • News
  • Tutorials
  • Forums
  • Tags
  • Users
Tutorial News Comments FAQ Related Articles

How to launch Apache webserver using Docker file on Ubuntu 21.04

  • 00:35 lsb_release -a
  • 00:48 apt list --installed | grep docker
  • 01:04 docker images
  • 01:12 vi dockerfiles/dockerfile
  • 01:49 docker build -t webserver dockerfiles/.
  • 02:30 docker images
  • 02:48 docker run -itd webserver
  • 03:10 docker ps
  • 03:26 docker inspect vigorous_cerf | grep IP
{{postValue.id}}

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

Capture

By this to launch Apache webserver using Docker file on Ubuntu 21.04 have been completed

Tags:
connor
Author: 

Comments ( 0 )

No comments available

Add a comment
{{postCtrl.cmtErrMsg}}

Frequently asked questions ( 5 )

Q

For what purpose does the "docker ps" command is used?

A

It is used to view the process status of the containers.

Q

How to list the containers with size?

A

To list containers with size use the command "docker ps –s"

Q

How to remove a container?

A

To remove a container use the command "docker rm "

Q

How to view the IP address of the specific docker container?

A

To view the IP address of the specific docker container use the command "docker inspect | grep IP"

Q

What is the use of the Docker file?

A

Using docker build users can create an automated build that executes several command-line instructions in succession.

Back To Top!
Rank
User
Points

Top Contributers

userNamenaveelansari
135850

Top Contributers

userNameayanbhatti
92510

Top Contributers

userNamehamzaahmed
32150

Top Contributers

1
userNamelinuxhelp
31040

Top Contributers

userNamemuhammadali
24500
Can you help Gibbson ?
How do i run both nginx and apache in same instance on centos

Hi...,

my server is based centos operating system and my webserver is already running on Apache.... i need to run both apache and nginx on same instance ... please help me to implement this concept...

Networking
  • Routing
  • trunk
  • Netmask
  • Packet Capture
  • domain
  • HTTP Proxy
Server Setup
  • NFS
  • KVM
  • Memory
  • Sendmail
  • WebDAV
  • LXC
Shell Commands
  • Cloud commander
  • Command line archive tools
  • last command
  • Shell
  • terminal
  • Throttle
Desktop Application
  • Linux app
  • Pithos
  • Retrospect
  • Scribe
  • TortoiseHg
  • 4Images
Monitoring Tool
  • Monit
  • Apache Server Monitoring
  • EtherApe 
  • Arpwatch Tool
  • Auditd
  • Barman
Web Application
  • Nutch
  • Amazon VPC
  • FarmWarDeployer
  • Rukovoditel
  • Mirror site
  • Chef
Contact Us | Terms of Use| Privacy Policy| Disclaimer
© 2025 LinuxHelp.com All rights reserved. Linux™ is the registered trademark of Linus Torvalds. This site is not affiliated with linus torvalds in any way.