0

Trying to build a simple ubuntu apache web server docker image, I get an error while the docker build command tries installing packages. I am using the Ubuntu base image in Docker to do this. Below is the code in my Dockerfile;

FROM ubuntu
RUN apt-get update
RUN apt-get install apache2
RUN apt-get install apache2-utils
RUN apt-get clean
EXPOSE 80
CMD ["apache2ctl", "-D", "FOREGROUND"]

My Host OS is Mac OSX El Capitan, and the error I get when the build fails is;

The command '/bin/sh -c apt-get install apache2' returned a non-zero code: 1

and my docker build command is;

docker build -t="webserver" .

Any help please. Thanks in Advance.

Derick Alangi
  • 1,080
  • 1
  • 11
  • 31
  • Try running your container with the additional commandline switch `-it`, it should print the stdout and hopefully the error message from `apt-get` (from a [similar thread here](https://stackoverflow.com/a/39085298/1781026)) – chrki Aug 12 '17 at 13:11
  • @chrki, it's not yet at the run stage, I am still trying to create an image and -i is not available in `docker build`. – Derick Alangi Aug 12 '17 at 13:20
  • There should be an error message just above the error message you provided. Can you please include it ? – yamenk Aug 12 '17 at 14:35

1 Answers1

2

You should use the '-y' apt-get flag when building an image.

apt-get will ask you permission to continue with apache installation, and since you can't interact with the apt-get while building the image, you must pass the '-y' flag that means 'yes' to apt-get prompt.

Try changing it to:

FROM ubuntu
RUN apt-get update
RUN apt-get install apache2 -y
RUN apt-get install apache2-utils -y
RUN apt-get clean
EXPOSE 80
CMD ["apache2ctl", "-D", "FOREGROUND"]

or even:

FROM ubuntu
RUN apt-get update && apt-get install apache2 apache2-utils -y
RUN apt-get clean
EXPOSE 80
CMD ["apache2ctl", "-D", "FOREGROUND"]
dvd
  • 36
  • 1