build a container with php/apache

  1. we can search php and apache image on Docker Hub, we will use php:7.0-apache for this demo.

  2. create Dockerfile and src/index.php as below

    root@ubunu2004:~/docker_sample# tree
    .
    ├── Dockerfile
    └── src
    └── index.php
    1 directory, 2 files
    root@ubunu2004:~/docker_sample# cat  Dockerfile
    FROM php:7.0-apache
    COPY src/ /var/www/html
    EXPOSE 80
    root@ubunu2004:~/docker_sample# cat src/index.php
    <?php
    echo "Hello World!";
  3. build the container
    docker build -t hello_world .

  4. run the container
    docker run -p 82:80 hello_world
    then you can verify it on http://192.168.0.43:82/

  5. if you want mapping the index.php to container, you can start it with
    docker run -p 82:80 -v /root/docker_sample/src/:/var/www/html/ hello_world
    now if you update index.php, you will get the change immediately on http://192.168.0.43:82/

  6. you can push this image to Docker Hub
    root@ubunu2004:~/docker_sample# docker images
    REPOSITORY TAG IMAGE ID CREATED SIZE
    hello_world latest dc8c649d4e8b 19 minutes ago 368MB
    root@ubunu2004:~/docker_sample# docker run -it -d hello_world:latest
    root@ubunu2004:~/docker_sample# docker ps
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    d2963444e718 hello_world:latest "docker-php-entrypoi…" 10 seconds ago Up 6 seconds 80/tcp laughing_williamson
    root@ubunu2004:~/docker_sample# docker commit d2963444e718 zhuby1973/php:1
    sha256:1f2007f4786c344c8007b574af6f71b7604431c6d6cce0e2091e6adf1a8c8621
    root@ubunu2004:~/docker_sample# docker push zhuby1973/php:1

3 Replies to “build a container with php/apache”

Leave a Reply

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