---
title: "How to Set up an Apache Docker Container"
description: "If you're new to Docker or just need to know how to setup a Apache Docker container, this step-by-step tutorial is for you!"
canonical: "https://adamtheautomator.com/apache-docker/"
---

# How to Set up an Apache Docker Container

> If you're new to Docker or just need to know how to setup a Apache Docker container, this step-by-step tutorial is for you!

Source: https://adamtheautomator.com/apache-docker/

---

ATA Learning

Tap to hide

[

ATA Learning

](/)

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Search for:  

*   [](https://twitter.com/adbertram)
*   [](https://github.com/Adam-the-Automator)
*   [](https://www.linkedin.com/company/adam-the-automator-llc)
*   [](/feed/)

![How to Set up an Apache Docker Container](https://adamtheautomator.com/wp-content/uploads/2021/08/How-to-Set-up-an-Apache-Docker-Container.jpg)

# How to Set up an Apache Docker Container

[![](https://secure.gravatar.com/avatar/2beb65fca997135120ed98dc6a2e57dcdf1a7d7d2f5ff687b5d91dc7ccd7a6b5?s=192&d=mm&r=g)Sagar](https://adamtheautomator.com/author/shanky-mendiratta/)17 August 20215 min. read

Categories: [DevOps](/category/devops/)

Tags:[Apache](/tag/apache/)[Docker](/tag/docker/)

Table of Contents

*   [Prerequisites](#prerequisites)
*   [Setting up the Apache Docker Container](#setting-up-the-apache-docker-container)
*   [Running the Apache Container using Docker Command.](#running-the-apache-container-using-docker-command)
*   [Running Apache Docker Container from Docker file](#running-apache-docker-container-from-docker-file)
*   [Conclusion](#conclusion)

If you’re new to Docker and containers, then setting up [Apache Docker Container](https://www.docker.com/resources/what-container) is a great way to start. Creating an application on Docker is a huge benefit because of its light-weighted technology and security.

In this tutorial, you will learn how to set up an Apache Docker Container on Ubuntu. Use this tutorial to learn to get started with Docker and come away with an Apache webserver too!

## **Prerequisites**

If you’d like to follow along step-by-step, ensure you have the following and Ubuntu 14.04.4 LTS or greater machine with Docker installed in this tutorial. This tutorial uses [Ubuntu 18.04.5 LTS](https://releases.ubuntu.com/18.04/) with Docker v19.03.8 and a public IP address of 13.213.48.113.

Related:[Related: How to Install and Use Docker on Ubuntu (In the Real World)](https://adamtheautomator.com/docker-ubuntu/)

## Setting up the Apache Docker Container

Assuming you’ve installed Docker already, let’s first set up the Apache container. Later, you’ll learn how to start it up.

One of the easiest ways to quickly bring up an Apache Docker container is downloading an existing container image from the official Docker registry [Docker Hub](https://hub.docker.com/). For this example, you’ll be downloading and running a Docker container called [Apache](https://httpd.apache.org/).

With a few Docker commands, you’ll be running an instance of Apache in no time. To do so, follow the steps below.

> _Note: This tutorial does not cover running Docker commands in-depth. To learn more about Docker commands, visit the [Docker command line documentation](https://docs.docker.com/engine/reference/commandline/cli/) page._

1\. Open a terminal on your Ubuntu machine.

2\. Download the Docker image, which contains Apache called `httpd`, by running the [`docker pull`](https://docs.docker.com/engine/reference/commandline/pull/) command below. This command will download or pull the Apache image from the Docker registry, as shown below.

```powershell
# Pulls the Docker Images from docker registry to your local machine.
docker pull httpd
```

The screenshot below shows the expected result when pulling the image from [Docker Hub](https://hub.docker.com/).

![Pulling the Apache image from Docker Hub](https://adamtheautomator.com/wp-content/uploads/2021/08/Untitled-2021-08-17T182656.808.png)

Pulling the Apache image from Docker Hub

3\. Next, confirm you’ve downloaded the image by running the [`docker images` command](https://docs.docker.com/engine/reference/commandline/images/) below to list all images available on your computer.

```powershell
# To check the docker images
docker images
```

As you can see below, you now have one Docker image, which is the image you downloaded from Docker Hub.

![Checking the Docker images](https://adamtheautomator.com/wp-content/uploads/2021/08/Untitled-2021-08-17T182916.357.png)

Checking the Docker images

## Running the Apache Container using Docker Command.

In the previous section, you downloaded the Docker image from the Docker hub. You’re now ready to create a container from that image. To run the Apache container, you will need to run the Docker command as follows:

1\. Invoke the [`docker run`](https://docs.docker.com/engine/reference/commandline/run/) command to create a new container based on your downloaded Apache Docker image.

```powershell
# Run a new docker container called docker-apache (--name)
# Map the local computer's port 80 to the container's port 80 (-p 80:80)
# In detached mode (-d)
# Using the Apache image
docker run -d --name docker-apache -p 80:80 -d httpd
```

The `docker run` command then returns the unique container ID of the container you’ve just created. Save this container id in the highlighted box below to the future if you wish to delete or remove the container.

Related:[Docker Exec: Your Goto Command for Running Commands in Docker](https://adamtheautomator.com/docker-ubuntu/)

![Running a new Docker container using an Apache image](https://adamtheautomator.com/wp-content/uploads/2021/08/Untitled-2021-08-17T183359.338.png)

Running a new Docker container using an Apache image

2\. Once the Apache container is running, verify if you can access the Apache web interface by navigating to _Public-Ip-address:80_ using your web browser. If you can see the same message, as you can see below, then you’ve successfully started your Apache Docker container.

> _Make sure Ubuntu 14.04.4 LTS Machine has a Port 80 inbound port allowed in the security group._

![Accessing the Apach](https://adamtheautomator.com/wp-content/uploads/2021/08/Untitled-2021-08-17T183518.004.png)

Accessing the Apach

3\. Finally, stop the container if you don’t need it running anymore by running the [`docker stop`](https://docs.docker.com/engine/reference/commandline/stop/) command below. This command will gracefully stop the container instance.

```powershell
# Stop the container with ID aaaee64a4512 Make sure to change the container ID value to yours.
# Note: specifying the first 12 characters of the container ID is enough.
docker stop aaaee64a4512
```

> _Alternatively, you can also stop a running container by specifying its name in the `docker stop` command (_`docker stop docker-apache`).

Related:[Docker Exec: Your Goto Command for Running Commands in Docker](https://adamtheautomator.com/docker-exec/)

## **Running Apache Docker Container from Docker file**

In the previous section, you learned how to launch an Apache Docker container by running the default httpd Docker image. What if you need to update the base image to display different content or expose it on a different port?

Deploying a container using Docker file allows you to remove the manual image creation step when you’re testing the same setup on a different OS. The Docker file approach is an automated script of Docker images.

Let’s create a Docker file and run a container from it.

1\. Create a folder named ~/_apache-server-docker-demo,_ then change (`cd`) the working directory to that folder.

```bash
mkdir ~/apache-server-docker-demo
cd ~/apache-server-docker-demo
```

2\. Create another file, copy/paste the below configuration and save the file as an _index.html_ inside of the ~/_apache-server-docker-demo_ directory. The _index.html_ file is an HTML page which will display **This tutorial will teach how to Run Apache container in docker** once container starts which you will see later in the course.

```markup
<!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 another file, copy/paste the below configuration, and save the file as _Docker file_ inside the ~/_apache-server-docker-demo_ directory. When complete, Docker will use this DockerFile to run all the commands necessary to build a new Docker image on top of any base image.

The _DockerFile_ below contains various steps/instructions that will build the Apache container:

*   `Maintainer`**–** [Maintainer](https://docs.docker.com/engine/reference/builder/#maintainer-deprecated) instruction provides information about the author who manages this file.
*   `FROM`**–** The [FROM](https://docs.docker.com/engine/reference/builder/#from) instruction initializes a new build stage and sets the Base Image for subsequent instructions. In the below code snippet, `centos:7` is the base image.
*   `COPY`**–** [COPY](https://docs.docker.com/engine/reference/builder/#copy) command copies a file from the host machine (Docker host) to the container. The \*\*\*\*_index.html_ you created earlier on Docker host will be copied to the containers _/var/www/html_ directory.
*   `EXPOSE`– The [EXPOSE](https://docs.docker.com/engine/reference/builder/#expose) instruction informs Docker that the container listens on the specified network ports at runtime. Apache webserver is by default exposed on `Port 80`.

```bash
# Instruction for Dockerfile to create a new image on top of the base image (httpd)
FROM httpd:2.4
MAINTAINER shanky@adamtheautomator.com
COPY index.html /var/www/html/
EXPOSE 80
```

4\. Next, verify all of the required files below in the folder by running the `tree` command.

![Verify all the required files](https://adamtheautomator.com/wp-content/uploads/2021/08/Untitled-2021-08-17T184021.380.png)

Verify all the required files

5\. Next, build the image by running the `docker build` command. The `t` flag is used to tag the image `apache-server` with `v1` and`.` signifies the present working directory.

```bash
# Building the docker Image
sudo docker build  -t apache-server:v1 .
```

![build the image by running the docker build command](https://adamtheautomator.com/wp-content/uploads/2021/08/Untitled-2021-08-17T184117.419.png)

build the image by running the `docker build` command

When Docker builds runs, it returns various attributes. You’ll see one of those attributes is REPOSITORY. The REPOSITORY name is `apache-server`, and the image is tagged with version `v1`, as shown below.

![Repository Attributes](https://adamtheautomator.com/wp-content/uploads/2021/08/Untitled-2021-08-17T184234.927.png)

Repository Attributes

6\. Finally, run the apache container using the newly built image by running the `docker run` command.

The `p` flag publishes a container’s port(s) to the host, which is `80:80`. The `-it` flag instructs Docker to allocate a [pseudo-terminal](https://en.wikipedia.org/wiki/Pseudoterminal) connected to the container’s stdin.

```bash
# Running the Apache container using the newly built image
docker run -it -p 80:80 apache-server:v1
```

7\. Finally, verify if you can access the Apache web interface by navigating to _Public-ip-address:80_ using your web browser. You’ll see this message on the web interface because you created the index.html file, and Docker copied it to the container when it started up.

![verify if you can access the Apache web interface](https://adamtheautomator.com/wp-content/uploads/2021/08/Untitled-2021-08-17T184431.347.png)

verify if you can access the Apache web interface

Related:[How to Set up an NGINX Reverse Proxy in Docker \[Step-by-Step\]](https://adamtheautomator.com/nginx-reverse-proxy-docker/)

## Conclusion

This tutorial aimed to help you through the process of setting up an Apache Docker container using Docker images. You learned how to launch Apache containers using Docker files, with which you are allowed to edit and build customize containers of your choice.

So what are you going to build on the Apache server Docker image?

Share this article

[Share on X](https://twitter.com/intent/tweet?url=https%3A%2F%2Fadamtheautomator.com%2Fapache-docker%2F&text=How%20to%20Set%20up%20an%20Apache%20Docker%20Container)[Share on Facebook](https://www.facebook.com/sharer/sharer.php?u=https%3A%2F%2Fadamtheautomator.com%2Fapache-docker%2F)[Share on LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fadamtheautomator.com%2Fapache-docker%2F)

## Related Posts

![](https://adamtheautomator.com/wp-content/uploads/2026/02/featured_image-13.webp)

### [Azure Container Apps: Instant Preview Environments per PR](/build-ephemeral-preview-environments-every-pr/)

Build isolated preview environments for every pull request using Azure Container Apps revision labels and Azure DevOps pipelines with scale-to-zero economics.

![](https://adamtheautomator.com/wp-content/uploads/2025/11/55418e927e511ae263219c072e27d637c2a967a5036de7020b329582db775c26.png)

### [Automating Docker Container Health Checks with Python and Local Notifications](/docker-health-checks-python/)

Docker's built-in health checks are passive—they tell Docker when a container fails, but do they tell you? In this tutorial, we'll build a lightweight Python monitoring system that runs entirely on your infrastructure with zero external dependencies. You'll learn to detect container failures in real-time, send instant alerts, and maintain a complete audit log of every state change.

![](https://adamtheautomator.com/wp-content/uploads/2023/07/gitea-docker.jpg)

### [Gitea Docker: Your Ultimate Self-Hosted Git Solution](/gitea-docker/)

Learn how to install a Gitea Docker instance and self-host Git repositories securely in this ATA Learning tutorial!

## Categories

*   [IT Ops](/category/it-ops/)
*   [Cloud](/category/cloud/)
*   [DevOps](/category/devops/)
*   [Home Ops](/category/home-ops/)
*   [Information Security](/category/infosec/)
*   [Software Development](/category/software-development/)

## Site

*   [Home](/)
*   [Tutorials](/tutorials/)
*   [Instructors](/author/)
*   [Advertising](/advertising/)
*   [Recommended Resources](/resources/)
*   [About Adam](/about-adam/)

Copyright 2026© ATA Learning | [Privacy Policy](/privacy/)
