How to Set up an Apache Docker Container


VPN offers!

1. NordVPN

2. Surfshark

3. ExpressVPN

What is a Docker Container?
Docker containers are software-only lightweight operating environments that run on top of the Linux kernel. They provide an easier way to build, deploy and manage applications in development and production. The versatility of these small but powerful packages allows them to be used as both hosting platforms for running pre-built services or microservices, such as web servers or databases, while also being able to use their own individual application specific instructions when needed by the developer.

The “install apache in docker container” is a process that allows users to set up an Apache Docker Container. This process is simple and easy, but can be time-consuming if you have not done it before.

How to Set up an Apache Docker Container

Setting up Apache Docker Container is a fantastic place to start if you’re new to Docker and containers. Docker’s lightweight technology and security make developing an application a major advantage.

You will learn how to set up an Apache Docker Container on Ubuntu in this article. This article will teach you how to get started with Docker while also providing you with an Apache webserver.


If you want to follow along with this tutorial step by step, make sure you have the following and an Ubuntu 14.04.4 LTS or higher system with Docker installed. This tutorial makes use of Ubuntu 18.04 LTS, Docker v19.038, and a public IP address of

How to Install and Use Docker on Ubuntu (Related) (In the Real World)

Configuring an Apache Docker Container

Let’s start with the Apache container, assuming you’ve previously installed Docker. You’ll learn how to start it up later.

Downloading an existing container image from the official Docker registry Docker Hub is one of the simplest methods to rapidly start an Apache Docker container. You’ll be downloading and running an Apache Docker container in this example.

You’ll be launching an instance of Apache in no time with just a few Docker instructions. Follow the instructions below to do so.

This article does not go through how to execute Docker commands in detail. Visit the Docker command line documentation page to learn more about Docker commands.

1. On your Ubuntu system, open a terminal.

2. Run the docker pull command to get the Docker image that includes Apache named httpd. As demonstrated below, this command will download or retrieve the Apache image from the Docker registry.

# Downloads Docker Images from the Docker Registry to your computer. httpd docker pull

When you pull the image from Docker Hub, you should get the following result.

Using Docker Hub to get the Apache image Using Docker Hub to get the Apache image

3. Run the docker images command to list all images accessible on your machine to ensure you’ve downloaded the image.

# Verify the Docker images images docker

You now have one Docker image, which is the image you got from Docker Hub, as seen below.

Examining Docker images Examining Docker images

Docker Command is used to run the Apache Container.

You downloaded the Docker image from the Docker hub in the previous step. You may now make a container out of that picture. You must execute the Docker command as follows to launch the Apache container:

1. Use the docker run command to build a new container based on the Apache Docker image you obtained.

# Start a docker container named docker-apache (—name) # Map port 80 on the local computer to port 80 on the container (-p 80:80) # Disconnected mode (-d) # docker run -d —name docker-apache -p 80:80 -d Using the Apache image httpd

The unique container ID of the container you just created is returned by the docker run command. If you want to delete or remove the container in the future, save the container id in the highlighted area below.

Docker Exec: Your Go-To Command for Docker Command Execution

Using an Apache image to start a new Docker container Using an Apache image to start a new Docker container

2. Once the Apache container is up and running, use your web browser to go to Public-Ip-address:80 to see whether you can access the Apache web interface. If you receive the same message as the one below, your Apache Docker container has launched successfully.

Make sure Port 80 is authorized in the security group on Ubuntu 14.04.4 LTS Machine.

Getting to the Apach Getting to the Apach

3. Finally, if you no longer need the container, use the docker stop command to terminate it. The container instance will be gently terminated using this command.

# Terminate the aaaee64a4512 container. Make care to replace the container ID with your own. # It is sufficient to supply the first 12 characters of the container ID. aaaee64a4512 docker halt

You can also use the docker stop command to stop a running container by supplying its name (docker stop docker-apache).

Docker Exec: Your Go-To Command for Docker Command Execution

Using a Docker file to run an Apache Docker Container

You learnt how to start an Apache Docker container by executing the default httpd Docker image in the previous section. What if you need to change the basic image’s content or expose it on a different port?

When testing the same configuration on a different OS, utilizing a Docker file to deploy a container enables you to skip the manual image generation process. The Docker file technique is a Docker image script that is run automatically.

Let’s create a Docker file and use it to start a container.

1. Create a folder called /apache-server-docker-demo, then change (cd) to it.

/apache-server-docker-demo/mkdir /apache-server-docker-demo cd

2. In the /apache-server-docker-demo directory, create a new file and copy/paste the following settings. Save the file as index.html. The index.html file is an HTML page that will be shown on the screen. This lesson will show you how to start an Apache container in Docker, which you will see later in the course.

<!DOCTYPE html> <html lang=”en”> <head> <meta charset=”UTF-8″> <title>This tutorial will teach how to Run Apache container in docker .</title> </head> <body> <h1>This tutorial will teach how to Run Apache container in docker , lets GO!</h1> </body> </html>

3. Create a new file, put the following settings into it, and save it as a Docker file in the /apache-server-docker-demo directory. When Docker is finished, it will utilize this DockerFile to perform all of the tasks required to create a new Docker image from any base image.

The following DockerFile provides multiple steps/instructions for constructing the Apache container:

  • Maintainer– The maintainer instruction gives details about the author who is in charge of this file.
  • FROM– The FROM command establishes the Base Image for following instructions and starts a new construction stage. The basis image in the code excerpt below is centos:7.
  • COPY– The COPY command copies a file from the host computer to the container. The index.html file you prepared on Docker host will be transferred to the containers’ /var/www/html directory.
  • EXPOSE– The EXPOSE directive tells Docker that at runtime, the container listens on the given network ports. The default port for the Apache webserver is 80.

FROM httpd:2.4 MAINTAINER [email protected] # Instructions for Dockerfile to generate a new image on top of the base image (httpd) EXPOSE 80 COPY index.html /var/www/html/

4. Run the tree command to validate all of the needed files in the folder below.

Check all of the necessary files.Check all of the necessary files.

5. Run the docker build command to create the image. The t option is used to mark the image apache-server as v1 and. is used to indicate the current working directory.

sudo docker build -t apache-server:v1 # Creating the Docker Image

run the docker build command to create the image run the docker build command to create the image

When a Docker build completes, it returns a number of properties. REPOSITORY is one of the traits you’ll notice. The picture is labeled with version v1 and the REPOSITORY name is apache-server, as seen below.

Attributes for RepositoriesAttributes for Repositories

6. Finally, use the docker run command to start the apache container using the freshly created image.

The p flag informs the host of a container’s port(s), which are 80:80. Docker allocates a pseudo-terminal attached to the container’s stdin when the -it option is used.

# Using the freshly created image, execute docker run -it -p 80:80 apache-server:v1 to start the Apache container.

7. Finally, use your web browser to go to Public-ip-address:80 to see whether you can access the Apache web interface. Because you built the index.html file, Docker copied it to the container when it started up, you’ll see this message on the web interface.

Check that the Apache web interface is accessible.Check that the Apache web interface is accessible.

Related: [Step-by-Step] How to Set Up an NGINX Reverse Proxy in Docker


This guide was created to assist you in setting up an Apache Docker container using Docker images. You learnt how to start Apache containers using Docker files, which enable you to change and configure containers to your liking.

So, what are your plans for the Docker image of the Apache server?

The “apache docker-compose” is a tool that allows users to quickly set up an Apache Docker container. This tool simplifies the process of creating and managing containers.

Related Tags

  • docker apache image
  • how to check apache version in docker container
  • install apache in docker container ubuntu
  • docker-apache php
  • docker apache windows