0

I'm trying to deploy PHP files in Apache container using Dockerfile, Dockerfile on console shows successfully built and tagged but after running the container, i couldn't access the container IP or Container URL in local browser

Dockerfile

FROM ubuntu:bionic
RUN apt-get update
RUN apt-get install -y software-properties-common && \add-apt-repository ppa:ondrej/php && apt-get update
RUN apt-get -y upgrade && DEBIAN_FRONTEND=noninteractive apt-get -y install \
apache2 php7.0 php7.0-mysql libapache2-mod-php7.0
RUN sed -i "s/short_open_tag = Off/short_open_tag = On/" /etc/php/7.0/apache2/php.ini
RUN sed -i "s/error_reporting = .*$/error_reporting = E_ERROR | E_WARNING | E_PARSE/" /etc/php/7.0/apache2/php.ini

ENV APACHE_RUN_USER www-data
ENV APACHE_RUN_GROUP www-data
ENV APACHE_LOG_DIR /var/log/apache2
ENV APACHE_LOCK_DIR /var/lock/apache2
ENV APACHE_PID_FILE /var/run/apache2.pid

EXPOSE 80
ADD www /var/www/site
ADD apache-config.conf /etc/apache2/sites-enabled/000-default.conf
ADD hosts /etc/hosts
CMD /usr/sbin/apache2ctl -D FOREGROUND ```
1

You need to expose the container ports locally using either:

  • docker run --rm -it -p 8080:80 myapp
  • or a docker-compose.yml file:
services:
  myapp:
    image: myapp:tag
    ports:
    - 8080:80

Then, you'll be able to curl localhost:8080.

0

A side-note (sorry, I haven't got enough reputation to post direct comments yet): I see you are basing your image off of Ubuntu (FROM ubuntu:bionic) and then installing Apache... I would suggest using an image that's already tailored for this function, such as the Apache HTTP Server.

Not the answer you're looking for? Browse other questions tagged or ask your own question.