DOCKER PULL HTTPD

The Apache HTTP Server, colloquially called Apache, is a Web server application notable for playing a key role in the initial growth of the World Wide Web. The picture above is one of the example of docker official images, you can download the httpd image from the docker official and start the container

  • docker pull httpd

    docker run -itd myhttpd -p 8080:80 httpd:latest

  • # run means you make a container

    Test whether the container has started successfully, you can open the web page based on your local host, mine is 172.16.98.154:8080 and it will show like,


    DOCKER PUSH HTTPD

    After you success to run HTTPD images, now you can push your image to your Docker Hub account, make sure you have login using docker login command, and check the images and container list, now the first step you have to tag the httpd images by the command,

  • docker tag 216 liaastuti/httpd:latest

    docker push liaastuti/httpd:latest

  • # 216 is the container id
    # liaastuti is my docker account
    # httpd:latest is the version of httpd that we want to upload
    # push means we push the images (httpd) to the docker hub (account : liaastuti) with the latest version


    To make sure that the image is successfully uploaded to you docker hub account, now, you can pull the image that you have uploaded, but first, please remove the image that you have uploaded, by command docker images, because i will pull my docker httpd images, so i will remove liaastuti/httpd images by command docker rmi liaastuti/httpd, after successful you can pull httpd from your docker hub account, with following command,

  • docker pull liaastuti/httpd


  • HELLO WORLD

    After we learn how to pull and push Docker HTTPD images, now we can change the default text of web test, which is "It Works!" into words or sentence that you want, for example, i want to show "Hello World", Now, you have to run the container first, by following command

  • mkdir /myweb

    cd /myweb

    echo "Hello World">index.html

    cat index.html

    docker run -itd --name myweb1 -v /myweb:/usr/local/apache2/htdocs -p 8082:80 httpd

  • # mkdir means make directory
    # myweb means path that make by myself
    # cd means go to directory that you want
    # echo means command to make "Hello World"
    # index.html means the default of apache httpd
    # cat means to show "Hellow World" at your terminal
    # 8082 means the port corresponding to the virtual machine and also can be on different containers
    # 80 means httpd port number
    # /myweb:/usr/local/apache2/htdocs means the path default of httpd

    Now you can see the result on your browser, for example my port is 172.16.98.154:8082. You can see the result by the following picture below,

    Change the httpd storage path

    Now you can make different apache by replacing default apache into hi.htm or whatever you want, but make sure that the directory has not been used by another test, or you just can change the directory. So you can run this command,

  • mkdir -p /data

    cd /myweb

    echo "hi">hi.htm

    docker run -itd --name myweb1 -v /myweb:/usr/local/apache2/htdocs -p 8080:80 httpd

  • # -p means if you want to create directory of long path

    You can get the information about images and containers by following command,

  • docker inspect container ID

  • You will see information like this:

    It can be seen that we put the httpd webpage under /data , so we can test the webpage when /data creating echo "hi" > hi.htm . Now here is the result,

    How to change the current path and keep the original data?

    Now, we can try to keep the original data while we want to change the current path, first create a volume by following command,

  • docker volume ls

    docker create volume --name webdata

  • Then test the http container under the custom path,

  • docker run -itd --name myweb1 -p 8081:80 -v webdata:/usr/local/apache2/htdocs httpd

    docker inspect myweb1

  • the inspect command will show like the information picture below,

    After that you can try to open the web page by your IP Address + Port Number whether it is successful or no.