patternbashMinor
Dockerfile to install Apache
Viewed 0 times
dockerfileinstallapache
Problem
I'm getting started with Docker, and I've set up a very simple image built from a Dockerfile. It's based
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
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/bashFROM 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 >/dev/null
RUN wget http://mirrors.ukfast.co.uk/sites/ftp.apache.org//apr/apr-1.5.2.tar.gz >/dev/null
RUN tar -xvzf apr-1.5.2.tar.gz >/dev/null
WORKDIR /install-files/apache/apr-1.5.2
RUN ./configure >/dev/null
RUN make >/dev/null
RUN make install >/dev/null
WORKDIR /install-files/apache
RUN wget http://apache.mirror.anlx.net//apr/apr-util-1.5.4.tar.gz >/dev/null
RUN tar -xvzf apr-util-1.5.4.tar.gz >/dev/null
WORKDIR /install-files/apache/apr-util-1.5.4
RUN ./configure --with-apr=/usr/local/apr/ >/dev/null
RUN make >/dev/null
RUN make install >/dev/null
WORKDIR /install-files/apache/
RUN apt-get -qq install libpcre3 libpcre3-dev >/dev/null
RUN wget http://mirror.ox.ac.uk/sites/rsync.apache.org//httpd/httpd-2.4.18.tar.gz >/dev/null
RUN tar -xvzf httpd-2.4.18.tar.gz >/dev/null
WORKDIR /install-files/apache/httpd-2.4.18
RUN ./configure --with-apr=/usr/local/apr/ >/dev/null
RUN make >/dev/null
RUN make install >/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 /Solution
Do you really have a good reason for this permission setup?
It's a bit ironic to use the
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
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
RUN chmod 777 /root/startup.shIt'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 >/dev/nullYou 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.Code Snippets
RUN chmod 777 /root/startup.shRUN tar -xvzf httpd-2.4.18.tar.gz >/dev/nullContext
StackExchange Code Review Q#116725, answer score: 4
Revisions (0)
No revisions yet.