Select Page

How to setup Apache webserver in Docker containers

How to setup Apache webserver in Docker containers

In our previous post on Docker web hosting, we saw the benefits of Docker that makes it suitable for specialized hosting at low costs.

In web hosting, there are many key components such as web server, email server, dns server, etc. that are required for the website functioning.

Setup and manage your Docker system



Today, we’ll discuss how to setup an Apache webserver in Docker container.

1. Create Apache Docker container

The first step is to create a Docker container with the Apache image ‘httpd’. This can be done using the command ‘docker run’, giving the Apache directory as parameter:

docker run -dit --name apache-web -v "$PWD":/usr/local/apache2/htdocs/ httpd:2.4


A container with the Apache webserver image was created, and listed, as seen from the ‘docker ps’ command.

Create Apache Docker container

Create Apache Docker container

2. Edit the Apache configuration file

Once the webserver container is created, the Docker container can be accessed using ‘docker exec’ command to generate a bash session.

The configuration file for the webserver would be in the folder ‘/usr/local/apache2/conf/’ and can be edited further to suit your requirements.


Edit the apache config file

Edit the apache config file


[ Are your spending too much time managing your Docker containers? Our Docker experts take care of your infrastructure and ensure its smooth functioning. ]

3. Enable PHP support in Apache

To enable PHP support in the Apache webserver, you would have to use an image with Apache and PHP support, say ‘php:7.0-apache'.

Also, other relevant modules such as php-mysql and tools such as curl, would have to be installed.

The apache webserver would be now running inside the container and can be verified from within the bash session.

Apache processes running in Docker container

Apache processes running in Docker container

Do you provide Docker hosting services?

Wish you had more time to focus on your business? Let us help you.

Our engineers will assist you to setup, monitor and manage your Docker infrastructure 24/7.


1 Comment

  1. docker: Error response from daemon: driver failed programming external connectivity on endpoint hardcore_goodall (bc97a359e5143431dceb035960c7590ecad6c45dd38fc89feee808a4de8686bd): Error starting userland proxy: listen tcp bind: address already in use.


Submit a Comment

Your email address will not be published. Required fields are marked *

Bobcares is a server management company that helps businesses deliver uninterrupted and secure online services. Our engineers manage close to 51,500 servers that include virtualized servers, cloud infrastructure, physical server clusters, and more.