Docker Hands-On Part 02

docker-hands-on-part-02

02. Working With Prebuilt Docker Images

Overview

Let’s say you have been assigned a task to migrate a website from a server to a container. So how do we get a container? The easy way is to create a container from a prebuilt image. Since we are hosting a website we will need a web server.

This lab has 5 goals;

  1. Explore Docker Hub: We have to find the web server images we want to try.
  2. Get and View httpd: Retrieve the httpd image from Docker Hub, run a container from the image, and view the results.
  3. Run the Website in httpd: Get the website content, add it to an httpd container, and view the webpage.
  4. Get and View Nginx: Retrieve the nginx image from Docker Hub, run a container from the image, and view the results.
  5. Run the website in Nginx: Add the website content to an nginx container and view the webpage.

When we hit the server from our browser, the web page will load. We want that same thing to happen with the containers. We’ll load the website into an httpd container and then when we hit it, it will get back to the same website. Lastly, we’ll host the site using nginx just like we did with httpd.

1. Explore Docker Hub

Navigate to the Docker Hub and find the httpd container (latest).

httpd-container

Step 01: Verify the docker service is running by using the below command.

$ docker ps -a
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES

Step 02: We can start by pulling the httpd docker from the Docker Hub.

$ docker pull httpd

Step 03: To see the docker images run the below command.

$ docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
httpd         latest    59bcd61b45fd   2 weeks ago    167MB

Step 04: Now we need to start our container

the port will be 8080 on the server and port 80 will be connected in to the container. (-p 8080:80)

-d –> detach mode

$ docker run --name httpd -p 8080:80 -d httpd:latest
016b3196078f73a0ea062024b4b6b82430a81aad1b02fe8329fa78997931fc

$ docker ps -a
CONTAINER ID   IMAGE          COMMAND              CREATED          STATUS          PORTS                                   NAMES
016b3196078f   httpd:latest   "httpd-foreground"   44 seconds ago   Up 43 seconds   0.0.0.0:8080->80/tcp, :::8080->80/tcp   httpd

Step 05: Now we can test it if the httpd is running using a web browser.

Enter your server’s public IP in the web browser. You can see it.

Total
0
Shares
Leave a Reply

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

Previous Post
why-use-obsidian-for-software-development?

Why use Obsidian for software development?

Next Post
my-coding-adventure:-balancing-a-full-time-job,-evening-classes,-and-a-drum-&-bass-events-and-djing-side-hustle

My Coding Adventure: Balancing a full-time job, evening classes, and a Drum & Bass events and DJing side hustle

Related Posts