Building an Apache image – a Dockerfile example
Now that we're armed with a good understanding of the Dockerfile
constructs, in this recipe we will build a very simple Docker image that bundles the apache2
web server and also adds metadata to launch the apache2
application inside the container whenever a new container is created from this image.
Getting ready
Before we begin, the git
repository https://github.com/docker-cookbook/apache2 has a Dockerfile
to build an apache2
image, so clone the repository as shown in the following code:
$ git clone https://github.com/docker-cookbook/apache2.git
Now, go to the apache2
directory:
$ cd apache2$ cat DockerfileFROM alpine:3.6LABEL maintainer="Jeeva S. Chelladhurai <[email protected]>"RUN apk add --no-cache apache2 && \ mkdir -p /run/apache2 && \ echo "<html><h1>Docker Cookbook</h1></html>" > \ /var/www/localhost/htdocs/index.htmlEXPOSE 80ENTRYPOINT ["/usr/sbin/httpd", "-D", "FOREGROUND"...