Running apache2 server on ubuntu docker container

I am working on Ubuntu 14.04. I recently started to learn docker and I have a Ubuntu 14.04 container. I want to install and run apache2 on this container to get my hands dirty in cloud and servers. Can someone tell me the commands to run the apache2 server on a specific ip address(with port number) and URL?

3 Answers

Ok, I think you are more interested on creating a Dockerfile that runs with Apache so here we go. I provide instructions to install Apache with PHP and MySQL. If you just want Apache remove the PHP and MYSQL packages from apt install.

Even if you use Ubuntu 14, you can run Dockers with more recent Ubuntu distributions. I recommend to work with Apache 2.4 and 2.2 is End of Life (EOL).

You have to create a file called: Dockerfile

FROM ubuntu:19.04
ARG DEBIAN_FRONTEND=noninteractive
# That is not needed
# RUN echo "nameserver 8.8.8.8" > /etc/resolv.conf
RUN echo "Europe/Ireland" | tee /etc/timezone
# Note: You should install everything in a single line concatenated with
# && and finalising with apt autoremove && apt clean
# in order to save the maximum space on the layer.
# In order to use the less space possible, as every command is a layer
RUN apt-get update && apt-get install -y apache2 ntpdate libapache2-mod-php7.2 \
mysql-server php7.2-mysql php-dev libmcrypt-dev php-pear git && \
apt autoremove && apt clean
# Enable mod rewrite. Optional, required for CMS like WordPress to rewrite urls
RUN a2enmod rewrite
EXPOSE 80
CMD ["/usr/sbin/apache2", "-D", "FOREGROUND"]

Then you will do in the same directory:

sudo docker build -t trinity .

And to run it:

sudo docker run -d -p 80:80 trinity

If you need to enter interactively:

sudo docker exec -i -t trinity /bin/bash

Launching Apache web server using Docker is an extremely easy task.

Before starting, I may recommend you to follow these guides, that are really useful for understanding the steps of how-to-start with Docker - Run a simple application, Quickstart containers.

Regarding your Apache question: I may recommend you to follow this page, where you may find some useful recommendations of how-to-run Apache webserver on Docker.

If you'd like to run Docker container on some specific port, you may get started with the following - Docker networking guide.

Have a good luck!

1

Try : apt-get update && apt-get install apache2 -y

--> This is because docker is not storing app repository cache

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like