If you run your website from a pre-built base image, it will require a manual process to set up the container each time it runs. For repeatability and scalability, the container, and your website code should be made into an image. In this lab, you will start with a base webserver image, modify settings in the container for your website, and then create images from the container. You’ll demonstrate the importance of small changes to your container, and how they affect your image. Lastly, you will use your new images to create containers to see your hard work in action.
Learning Objectives
Successfully complete this lab by achieving the following learning objectives:
- Get and Run the Base Image
- Retrieve the
httpd 2.4
image from Docker hub. - Start a container from the
httpd
image.
- Retrieve the
- Install Tools and Code in the Container
- Log in to the container.
- Update the base image and install
git
. - Get website code from GitHub.
- Remove the default index page and copy the website files to
httpd
‘s web serving directory. - Log out of the container.
- Create an Image from the Container
- Find the template container’s ID.
- Create an image named
widgetfactory
with versionv1
from the container.
1. View the image information.Note: You can use the container’s name in place of its ID for
docker commit
. However, we will practice using the container ID in this lab.
- Clean up the Template for a Second Version
- Log in to the container.
- Remove temporary files and installed utilities.
- Log out of the container.
- Find the template container’s ID.
- Create a new image named
widgetfactory
with versionv2
from the container - View the image information.
- Delete the
v1
image since it is obsolete.
- Run Multiple Containers from the Image
- Start three containers from the
widgetfactory:v2
image with different published web ports. The exposed ports should be in the8000
to8999
range. - View the running containers in Docker.
- View the website from each container in a browser, using the three exposed web ports.
- Start three containers from the