# Apache Docker Setup ###### tags: `web develope` ## Before Works Make sure there is 3 directory: * **www**: store code of html, javascript and css * **logs**: store apache logs files * **conf**: store apache conf files Plus **httpd-foreground** and **Dockerfile** ``` shell= FROM debian:jessie ENV HTTPD_PREFIX /usr/local/apache2 ENV PATH $PATH:$HTTPD_PREFIX/bin RUN mkdir -p "$HTTPD_PREFIX" \ && chown www-data:www-data "$HTTPD_PREFIX" WORKDIR $HTTPD_PREFIX # install httpd runtime dependencies # https://httpd.apache.org/docs/2.4/install.html#requirements RUN apt-get update \ && apt-get install -y --no-install-recommends \ --------<snip>-------- COPY httpd-foreground /usr/local/bin/ EXPOSE 80 CMD ["httpd-foreground"] ``` the shell script **httpd-foreground** is used for start/exec httpd sevice. ```shell= #!/bin/bash set -e # Apache gets grumpy about PID files pre-existing rm -f /usr/local/apache2/logs/httpd.pid exec httpd -DFOREGROUND ``` Make sure you have privilege to execute httpd-foreground ```shell= ~/apache$ chmod +x httpd-foreground ``` ## Docker Build Up From Image to Container ```shell= ~/apache$ docker build -t httpd . ~/apache$ docker images httpd REPOSITORY TAG IMAGE ID CREATED SIZE httpd latest da1536b4ef14 23 seconds ago 195.1 MB ~/apache$ docker run -p 80:80 -v $PWD/www/:/usr/local/apache2/htdocs/ -v $PWD/conf/httpd.conf:/usr/local/apache2/conf/httpd.conf -v $PWD/logs/:/usr/local/apache2/logs/ -d httpd ```
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up