You've already forked devops-exercises
Add containers questions and exercises
Added also a couple of storage questions.
This commit is contained in:
107
exercises/containers/solutions/commit_image.md
Normal file
107
exercises/containers/solutions/commit_image.md
Normal file
@@ -0,0 +1,107 @@
|
||||
# Create Images on The Fly
|
||||
|
||||
## Requirements
|
||||
|
||||
Have at least one image locally (run `podman image ls` to confirm).<br>
|
||||
If you don't have images locally, run simply `podman pull nginx:alpine`.
|
||||
|
||||
## Objectives
|
||||
|
||||
1. Run a container using a web server image (e.g. httpd, nginx, ...)
|
||||
- Bind container's port 80 to local port 80
|
||||
- Run it in detached mode
|
||||
- Name should nginx_container
|
||||
2. Verify the web server runs and accessible
|
||||
3. Create an HTML file with the following content and copy it to the container to the container to path where it will be accessed as an index file
|
||||
|
||||
```
|
||||
<html>
|
||||
<head>
|
||||
<title>It's a me</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Mario</h1>
|
||||
</body>
|
||||
```
|
||||
|
||||
4. Create an image out of the running container and call it "nginx_mario"
|
||||
5. Tag the container with "mario" tag
|
||||
6. Remove the original container (container_nginx) and verify it was removed
|
||||
7. Create a new container out of the image you've created (the same way as the original container)
|
||||
8. Run `curl 127.0.0.1:80`. What do you see?
|
||||
9. Run `podman diff` on the new image. Explain the output
|
||||
|
||||
## Solution
|
||||
|
||||
```
|
||||
# Run the container
|
||||
podman run --name nginx_container -d -p 80:80 nginx:alpine
|
||||
|
||||
# Verify web server is running
|
||||
curl 127.0.0.1:80
|
||||
# <!DOCTYPE html>
|
||||
# <html>
|
||||
# <head>
|
||||
# <title>Welcome to nginx!</title>
|
||||
|
||||
# Create index.html file
|
||||
cat <<EOT >>index.html
|
||||
<html>
|
||||
<head>
|
||||
<title>It's a me</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Mario</h1>
|
||||
</body>
|
||||
EOT
|
||||
|
||||
# Copy index.html to the container
|
||||
podman cp index.html nginx_container:/usr/share/nginx/html/index.html
|
||||
|
||||
# Create a new image out of the running container
|
||||
podman commit nginx_container nginx_mario
|
||||
|
||||
# Tag the image
|
||||
podman image ls
|
||||
# localhost/nginx_mario latest dc7ed2343521 52 seconds ago 25 MB
|
||||
podman tag dc7ed2343521 mario
|
||||
|
||||
# Remove the container
|
||||
podman stop nginx_container
|
||||
podman rm nginx_container
|
||||
podman ps -a # no container 'nginx_container'
|
||||
|
||||
# Create a container out of the image
|
||||
podman run -d -p 80:80 nginx_mario
|
||||
|
||||
# Check the container created from the new image
|
||||
curl 127.0.0.1:80
|
||||
#<html>
|
||||
#<head>
|
||||
#<title>It's a me</title>
|
||||
#</head>
|
||||
#<body>
|
||||
#<h1>Mario</h1>
|
||||
#</body>
|
||||
|
||||
# Run diff
|
||||
podman diff nginx_mario
|
||||
|
||||
C /etc
|
||||
C /etc/nginx/conf.d
|
||||
C /etc/nginx/conf.d/default.conf
|
||||
A /run/nginx.pid
|
||||
C /usr/share/nginx/html
|
||||
C /usr/share/nginx/html/index.html
|
||||
C /var/cache/nginx
|
||||
C /var
|
||||
C /var/cache
|
||||
A /var/cache/nginx/client_temp
|
||||
A /var/cache/nginx/fastcgi_temp
|
||||
A /var/cache/nginx/proxy_temp
|
||||
A /var/cache/nginx/scgi_temp
|
||||
A /var/cache/nginx/uwsgi_temp
|
||||
|
||||
# We've set new index.html which explains why it's changed (C)
|
||||
# We also created the image while the web server is running, which explains all the files created under /var
|
||||
```
|
||||
@@ -3,6 +3,7 @@
|
||||
1. Run a containerized web server in the background and bind its port (8080) to a local port
|
||||
2. Verify the port (8080) is bound
|
||||
3. Reach the webserver from your local host
|
||||
4. Now run the same web application but bound it to the local port 8080
|
||||
|
||||
## Solution
|
||||
|
||||
@@ -18,4 +19,6 @@ $ curl http://0.0.0.0:41203 # use the port from the output of the previous comma
|
||||
<head>
|
||||
<title>Test Page for the HTTP Server on Red Hat Enterprise Linux</title>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
|
||||
$ podman run -d -p 8080:8080 httpd
|
||||
```
|
||||
|
||||
35
exercises/containers/solutions/sharing_images.md
Normal file
35
exercises/containers/solutions/sharing_images.md
Normal file
@@ -0,0 +1,35 @@
|
||||
# Sharing Images
|
||||
|
||||
## Requirements
|
||||
|
||||
Have at least one image locally (run `podman image ls` to confirm).<br>
|
||||
If you don't have images locally, run simply `podman pull httpd`.
|
||||
|
||||
## Objectives
|
||||
|
||||
1. Choose an image and create an archive out of it
|
||||
2. Check the archive size. Is it different than the image size? If yes, what's the difference? If not, why?
|
||||
3. Copy the generated archive to a remote host
|
||||
4. Load the image
|
||||
5. Verify it was loaded and exists on the remote host
|
||||
|
||||
## Solution
|
||||
|
||||
```
|
||||
# Save image as an archive
|
||||
podman save -o httpd.tar httpd
|
||||
|
||||
# Check archive and image sizes
|
||||
du -sh httpd.tar # output: 143MB
|
||||
podman image ls | grep httpd # output: 149MB
|
||||
# The archive is obviously smaller than the image itself (6MB difference)
|
||||
|
||||
# Copy the archive to a remote host
|
||||
rsync -azc httpd.tar USER@REMOTE_HOST_FQDN:/tmp/
|
||||
|
||||
# Load the image
|
||||
podman load -i /tmp/httpd.tar
|
||||
|
||||
# Verify it exists on the system after loading
|
||||
podman image ls
|
||||
```
|
||||
Reference in New Issue
Block a user