RHCSA Rapid Track
In this exercise, you will create a container that accesses web content in persistent storage provided by the container host.
Outcomes
You should be able to deploy a container with persistent storage.
On the workstation machine, log in as the student user with student as the password.
On the workstation machine, run the lab containers-storage start command.
This command runs a start script that determines if the servera machine is reachable on the network.
It also installs the container tools on servera.
[student@workstation ~]$lab containers-storage start
Procedure 16.4. Instructions
Use the
sshcommand to log in toserveraas thestudentuser. The systems are configured to use SSH keys for authentication, so a password is not required.[student@workstation ~]$ssh student@servera...output omitted...[student@servera ~]$Create the
/home/student/webcontent/html/directory, and then create anindex.htmltest page. You will use this directory as persistent storage when you deploy a web server container.Create the
~/webcontent/html/directory.[student@servera ~]$mkdir -p ~/webcontent/html/[student@servera ~]$Create the
index.htmlfile and add some content.[student@servera ~]$echo "Hello World" > ~/webcontent/html/index.html[student@servera ~]$Confirm that everyone has access to the directory and the
index.htmlfile. The container uses an unprivileged user that must be able to read theindex.htmlfile.[student@servera ~]$ls -ld webcontent/html/drwxrwxr-x. 2 student student 24 Aug 28 04:56 webcontent/html/[student@servera ~]$ls -l webcontent/html/index.html-rw-rw-r--. 1 student student 12 Aug 28 04:56 webcontent/html/index.html
Create an Apache HTTP Server container instance with persistent storage.
Log in to the
registry.lab.example.comregistry as theadminuser withredhat321as the password.[student@servera ~]$podman login registry.lab.example.comUsername:adminPassword:redhat321Login Succeeded!Create a detached container instance named
myweb. Redirect port 8080 on the local host to the container port 8080. Mount the~/webcontentdirectory from the host to the/var/wwwdirectory in the container. Add the:Zsuffix to the volume mount option to instruct thepodmancommand to relabel the directory and its content. Use theregistry.lab.example.com/rhel8/httpd-24:1-98image. The followingpodman runcommand is very long and should be entered as a single line.[student@servera ~]$podman run -d --name myweb -p 8080:8080 -v ~/webcontent:/var/www:Z registry.lab.example.com/rhel8/httpd-24:1-98...output omitted...Run the
podman pscommand to confirm that the container is running, and then use thecurlcommand to access the web content on port 8080.[student@servera ~]$podman psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 2f4844b376b7 registry.lab.example.com/rhel8/httpd-24:1-98 /usr/bin/run-http... About a minute ago Up About a minute ago 0.0.0.0:8080->8080/tcp myweb[student@servera ~]$curl http://localhost:8080/Hello World
In the preceding step, you used the
1-98tag to select a particular version of thehttpd-24image. There is a more recent version of that image in the classroom registry. Use theskopeo inspectcommand to get theregistry.lab.example.com/rhel8/httpd-24image details and retrieve the tag for that version. The followingskopeo inspectcommand is very long and should be entered as a single line.[student@servera ~]$skopeo inspect docker://registry.lab.example.com/rhel8/httpd-24{ "Name": "registry.lab.example.com/rhel8/httpd-24", "Digest": "sha256:bafa...a12a","RepoTags": [ "1-98", "1-104","1-105", "latest" ], ...output omitted...Under the
RepoTagssection, notice that there is a more recent version with the tag1-105.Stop and delete the
mywebcontainer, and then start a new container using the1-105image tag. Confirm that the web content in persistent storage has not changed.Stop and then delete the container.
[student@servera user]$podman stop myweb2f4844b376b78f8f7021fe3a4c077ae52fdc1caa6d877e84106ab783d78e1e1a[student@servera user]$podman rm myweb2f4844b376b78f8f7021fe3a4c077ae52fdc1caa6d877e84106ab783d78e1e1aRerun the
podman runcommand that you used in a previous step to start themywebcontainer, but replace the image tag1-98with1-105. The followingpodman runcommand is very long and should be entered as a single line.[student@servera ~]$podman run -d --name myweb -p 8080:8080 -v ~/webcontent:/var/www:Z registry.lab.example.com/rhel8/httpd-24:1-105...output omitted...Run the
podman pscommand to verify that the container is running. Use thecurlcommand to confirm that your persistent volume data are preserved, even though you started a new container.[student@servera ~]$podman psCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES a648c286c653 registry.lab.example.com/rhel8/httpd-24:1-105 /usr/bin/run-http... About a minute ago Up About a minute ago 0.0.0.0:8080->8080/tcp myweb[student@servera ~]$curl http://localhost:8080/Hello WorldExit from
servera.[student@servera ~]$exitlogout Connection to servera closed.[student@workstation ~]$
This concludes the guided exercise.