Dockerfile to install Apache I'm getting started with Docker, and I've set up a very simple image built from a Dockerfile. It's based FROM the ubuntu image, and I'm downloading and building apache from source.

I'm just curious if I'm on the right tracks, if there's a more "Docker" way of doing what I'm doing, or any other things that I could be doing different/better.

It's running in the default VM that Kitematic adds for me, and I'm building the image with docker build -t webserver ., then testing with docker run -p 80:80 -i -t webserver /bin/bash

FROM ubuntu:latest

RUN apt-get -qq  update -y
RUN apt-get -qq install build-essential -y

RUN mkdir install-files
WORKDIR /install-files
RUN mkdir apache
WORKDIR /install-files/apache
RUN apt-get -qq install wget -y &gt;/dev/null
RUN wget http://mirrors.ukfast.co.uk/sites/ftp.apache.org//apr/apr-1.5.2.tar.gz &gt;/dev/null
RUN tar -xvzf apr-1.5.2.tar.gz &gt;/dev/null
WORKDIR /install-files/apache/apr-1.5.2
RUN ./configure &gt;/dev/null
RUN make &gt;/dev/null
RUN make install &gt;/dev/null

WORKDIR /install-files/apache
RUN wget http://apache.mirror.anlx.net//apr/apr-util-1.5.4.tar.gz &gt;/dev/null
RUN tar -xvzf apr-util-1.5.4.tar.gz &gt;/dev/null
WORKDIR /install-files/apache/apr-util-1.5.4
RUN ./configure --with-apr=/usr/local/apr/ &gt;/dev/null
RUN make &gt;/dev/null
RUN make install &gt;/dev/null


WORKDIR /install-files/apache/
RUN apt-get -qq install libpcre3 libpcre3-dev &gt;/dev/null
RUN wget http://mirror.ox.ac.uk/sites/rsync.apache.org//httpd/httpd-2.4.18.tar.gz &gt;/dev/null
RUN tar -xvzf httpd-2.4.18.tar.gz &gt;/dev/null
WORKDIR /install-files/apache/httpd-2.4.18
RUN ./configure --with-apr=/usr/local/apr/ &gt;/dev/null
RUN make &gt;/dev/null
RUN make install &gt;/dev/null

RUN mkdir /tech
RUN ln -s /usr/local/apache2/ /tech/httpd

RUN apt-get -qq install nano -y
ADD startup.sh /root/startup.sh
RUN chmod 777 /root/startup.sh

WORKDIR /
Do you really have a good reason for this permission setup?


RUN chmod 777 /root/startup.sh





It's a bit ironic to use the -v flag of tar, and then redirecting the output to /dev/null here:


RUN tar -xvzf httpd-2.4.18.tar.gz &gt;/dev/null



You can drop that flag and the redirection, the outcome should be the same.



I'm not very familiar with Docker, but I'm wondering what will happen if any of the commands fail. For example, if make fails, you probably don't want to run the make install command that follows it.
I don't have a solution for that, but error handling is something to think about.



The repetitive redirections and duplicated strings don't look pretty, and look hard to maintain. There gotta be a better way. Perhaps you could put the shell commands into a proper .bash script, enjoy all the power of regular bash scripting (variables, functions), and in the docker file just fetch that script using wget, and then execute it.