Surya.dev
Published on

#1-Working With Prebuilt Docker Images

Authors

In this blog, i will explore Docker Hub for images that will run a website. Once my find suitable images, i will get them into your development environment and begin experimenting. I will run, stop, and delete containers from those images. I will also learn how to use existing data in containers.

Explore Docker Hub

  1. Sign in to Docker Hub.

  2. At the top of the page, search for "httpd".

  3. In the left-hand menu, filter for Official Images.

  4. Select the httpd project. Image httpd project docker hub
  5. At the top of the page, click the Tags tab.

  6. Under latest, select linux/amd64.

  7. Back in the list of available images, select nginx Image nginx docker hub
  8. Review the How to use this image section.

Get and View httpd

  1. In the Docker Instance, verify that docker is installed:

    docker ps
    
  2. Using docker, pull the httpd image:

    docker pull httpd
    
  3. Run the image:

    docker run --name httpd -p 8080:80 -d httpd
    
  4. Check the status of the container:

    docker ps
    
  5. In a web browser, test connectivity to the container:

    http://localhost:8080
    

Run a Copy of the Website in httpd

  1. Clone the Widget Factory Inc repository:

    git clone https://github.com/linuxacademy/content-widget-factory-inc
    
    
  2. Change to the content-widget-factory-inc directory:

    cd content-widget-factory-inc
    
  3. Check the files:

    ll
    
  4. Move to the web directory:

    cd web
    
  5. Check the files:

    ll
    
  6. Stop the httpd container:

    docker stop httpd
    
  7. Remove the httpd container:

    docker rm httpd
    
  8. Verify that the container has been removed:

    docker ps -a
    
  9. Run the container with the website data:

    docker run --name httpd -p 8080:80 -v $(pwd):/usr/local/apache2/htdocs:ro -d httpd
    
  10. Check the status of the container:

    docker ps
    
  11. In a web browser, check connectivity to the container:

    http://localhost:8080
    
    Image localhost

Get and View Nginx

  1. Using docker, pull the latest version of nginx:

    docker pull nginx
    
  2. Verify that the image was pulled successfully:

    docker images
    
  3. Run the container using the nginx image:

    docker run --name nginx -p 8081:80 -d nginx 
    
  4. Check the status of the container:

    docker ps
    
  5. Verify connectivity to the nginx container:

    http://localhost:8081
    
    Image localhost

Run a Copy of the Website in Nginx

  1. Stop the nginx container:

    docker stop nginx
    
  2. Remove the nginx container:

    docker rm nginx
    
  3. Verify that the container has been removed:

    docker ps -a
    
  4. Run the nginx container, and mount the website data:

    docker run --name nginx -v $(pwd):/usr/share/nginx/html:ro -p 8081:80 -d nginx
    
  5. Check the status of the container:

    docker ps
    
  6. In a web browser, verify connectivity to the container:

    <PUBLIC_IP_ADDRESS>:8081
    
  7. Stop the nginx container:

    docker stop nginx
    
  8. Remove the nginx container:

    docker rm nginx
    
  9. Verify that the container has been removed:

    docker ps -a
    

END