25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

25% off on first invoice for all services*

SPRING SALE

Use coupon

*Offer valid for new customers only

Need help?

Our experts have had an average response time of 11.43 minutes in March 2024 to fix urgent issues.

We will keep your servers stable, secure, and fast at all times for one fixed price.

How to setup Apache webserver in Docker containers

by | Nov 29, 2016

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

GET IN TOUCH WITH THE DOCKER EXPERTS NOW!

 

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

4. Enable SSL support

Most webservers require SSL support for encryption. You can setup Let’s Encrypt, the free SSL, in the Docker container. Let’s Encrypt would generate cert and key files, which can be used for encrypting the webserver.

The certificate and key files can be copied over to ‘/usr/local/apache2/conf/’ and specified in the httpd.conf file. Restart the apache webserver to enable SSL support.

[ Running a Docker infrastructure doesn’t have to be hard, or costly. Get world class Docker management services at affordable pricing. ]

5. Expose the webserver port

By default, port 80 is the webserver port. But the Docker container port cannot be accessed from outside the host machine.

A webserver is meant to be accessible from outside. So, we need to expose the host machine port to bind the port 80 in host to the webserver port in the container.

This can be done with the command ‘docker run -d -p 80:80 -t httpd:2.4′  while creating the webserver container. For using SSL with webserver, the https port 443 need to be exposed by forwarding host port 443 to container port 443.

In our post on ‘How to expose docker ports‘, we’ve discussed about exposing Docker ports to make the web server content in the container externally accessible.

6. Configure Apache webserver in custom OS

The image we used for Apache webserver is ‘docker http server’ based on Alpine Linux. You can install and configure Apache in your server OS, say Ubuntu.

For that, you need to first create a container with Ubuntu image and then install apache web server in it. The custom images can be uploaded to the repository.

At Bobcares, we maintain a private docker registry for our internal Docker infrastructure, with custom images that are secure and optimized.

If you’d like to know how to manage your Docker system and custom images to get the best out of them for your business, we’d be happy to talk to you.

 

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.

GET IN TOUCH WITH THE EXPERTS NOW!

var google_conversion_label = "owonCMyG5nEQ0aD71QM";

1 Comment

  1. prashant

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

    Reply

Submit a Comment

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

Categories

Tags

Privacy Preference Center

Necessary

Necessary cookies help make a website usable by enabling basic functions like page navigation and access to secure areas of the website. The website cannot function properly without these cookies.

PHPSESSID - Preserves user session state across page requests.

gdpr[consent_types] - Used to store user consents.

gdpr[allowed_cookies] - Used to store user allowed cookies.

PHPSESSID, gdpr[consent_types], gdpr[allowed_cookies]
PHPSESSID
WHMCSpKDlPzh2chML

Statistics

Statistic cookies help website owners to understand how visitors interact with websites by collecting and reporting information anonymously.

_ga - Preserves user session state across page requests.

_gat - Used by Google Analytics to throttle request rate

_gid - Registers a unique ID that is used to generate statistical data on how you use the website.

smartlookCookie - Used to collect user device and location information of the site visitors to improve the websites User Experience.

_ga, _gat, _gid
_ga, _gat, _gid
smartlookCookie
_clck, _clsk, CLID, ANONCHK, MR, MUID, SM

Marketing

Marketing cookies are used to track visitors across websites. The intention is to display ads that are relevant and engaging for the individual user and thereby more valuable for publishers and third party advertisers.

IDE - Used by Google DoubleClick to register and report the website user's actions after viewing or clicking one of the advertiser's ads with the purpose of measuring the efficacy of an ad and to present targeted ads to the user.

test_cookie - Used to check if the user's browser supports cookies.

1P_JAR - Google cookie. These cookies are used to collect website statistics and track conversion rates.

NID - Registers a unique ID that identifies a returning user's device. The ID is used for serving ads that are most relevant to the user.

DV - Google ad personalisation

IDE, test_cookie, 1P_JAR, NID, DV, NID
IDE, test_cookie
1P_JAR, NID, DV
NID
hblid

Security

These are essential site cookies, used by the google reCAPTCHA. These cookies use an unique identifier to verify if a visitor is human or a bot.

SID, APISID, HSID, NID, PREF
SID, APISID, HSID, NID, PREF