How to create a new Docker image?

maxresdefaultIn this article we’re going to build one new docker image with Apache and PHP installed and one php file for test.

Create a directory called “build”:

# mkdir ˜/build

Change to directory “build”:

# cd ˜/build

Create a new file called Dockerfile with the following content:

FROM centos
MAINTAINER Daniel Nascimento
RUN yum update -y
RUN yum install httpd php -y
ADD index.php /var/www/html/
CMD /usr/sbin/apachectl -D FOREGROUND

In the same directory create another file called index.php with the following content:


Finally it’s time of build our new image.

# docker build -t user/httpd .

Now we have a new image with apache and php installed. Then let’s create a new container using this image:

# docker run -t -i -p 80:80 user/httpd

To access our new container in your browser type the URL:


That’s it! 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *