Skip to content

Commit 52d518f

Browse files
committed
IntoTheDevOps: Add End-to-End Docker-Containers content
Signed-off-by: NotHarshhaa <reddyharshhaa12@gmail.com>
1 parent 44697a2 commit 52d518f

22 files changed

+1922
-0
lines changed

topics/containers/README.md

Lines changed: 1280 additions & 0 deletions
Large diffs are not rendered by default.

topics/containers/commit_image.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Create Images on The Fly
2+
3+
## Requirements
4+
5+
Have at least one image locally (run `podman image ls` to confirm).<br>
6+
If you don't have images locally, run simply `podman pull nginx:alpine`.
7+
8+
## Objectives
9+
10+
1. Run a container using a web server image (e.g. httpd, nginx, ...)
11+
- Bind container's port 80 to local port 80
12+
- Run it in detached mode
13+
- Name should nginx_container
14+
2. Verify the web server runs and accessible
15+
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
16+
17+
```
18+
<html>
19+
<head>
20+
<title>It's a me</title>
21+
</head>
22+
<body>
23+
<h1>Mario</h1>
24+
</body>
25+
```
26+
27+
4. Create an image out of the running container and call it "nginx_mario"
28+
5. Tag the container with "mario" tag
29+
6. Remove the original container (container_nginx) and verify it was removed
30+
7. Create a new container out of the image you've created (the same way as the original container)
31+
8. Run `curl 127.0.0.1:80`. What do you see?
32+
9. Run `podman diff` on the new image. Explain the output
33+
34+
## Solution
35+
36+
Click [here to view the solution](solutions/commit_image.md)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## Containerized DB
2+
3+
1. Run a container with a database of any type of you prefer (MySql, PostgreSQL, Mongo, etc.)
4+
2. Verify the container is running
5+
3. Access the container and create a new table (or collection, depends on which DB type you chose) for students
6+
4. Insert a row (or document) of a student
7+
5. Verify the row/document was added
8+
9+
Click [here for the solution](solutions/containerized_db.md)
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Containerized DB with Persistent Storage
2+
3+
1. Run a container with a database of any type of you prefer (MySql, PostgreSQL, Mongo, etc.)
4+
1. Use a mount point on the host for the database instead of using the container storage for that
5+
2. Explain why using the host storage instead of the container one might be a better choice
6+
2. Verify the container is running
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Containerized Web Server
2+
3+
1. Run a containerized web server in the background and bind its port (8080) to a local port
4+
2. Verify the port (8080) is bound
5+
3. Reach the webserver from your local host
6+
4. Now run the same web application but bound it to the local port 8080
7+
8+
Click [here for the solution](solutions/containerized_web_server.md)

topics/containers/image_layers.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Layer by Layer
2+
3+
### Objective
4+
5+
Learn about image layers
6+
7+
### Requirements
8+
9+
Make sure Docker is installed on your system and the service is started
10+
11+
```
12+
# Fedora/RHEL/CentOS
13+
rpm -qa | grep docker
14+
systemctl status docker
15+
```
16+
17+
### Instructions
18+
19+
1. Write a Dockefile. Any Dockefile! :) (just make sure it's a valid one)
20+
2. Build an image using the Dockerfile you've wrote
21+
3. Which of the instructions you've used, created new layers and which added image metadata?
22+
4. What ways are there to confirm your answer to the last question?
23+
5. Can you reduce the size of the image you've created?
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Multi-Stage Builds
2+
3+
### Objective
4+
5+
Learn about multi-stage builds
6+
7+
### Instructions
8+
9+
1. Without actually building an image or running any container, use the following Dockerfile and convert it to use multi-stage:
10+
11+
```
12+
FROM nginx
13+
RUN apt-get update \
14+
&& apt-get install -y curl python build-essential \
15+
&& apt-get install -y nodejs \
16+
&& apt-get clean -y
17+
RUN mkdir -p /my_app
18+
ADD ./config/nginx/docker.conf /etc/nginx/nginx.conf
19+
ADD ./config/nginx/k8s.conf /etc/nginx/nginx.conf.k8s
20+
ADD app/ /my_cool_app
21+
WORKDIR /my_cool_app
22+
RUN npm install -g ember-cli
23+
RUN npm install -g bower
24+
RUN apt-get update && apt-get install -y git \
25+
&& npm install \
26+
&& bower install \
27+
RUN ember build — environment=prod
28+
CMD [ “/root/nginx-app.sh”, “nginx”, “-g”, “daemon off;” ]
29+
```
30+
31+
2. What are the benefits of using multi-stage builds?
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
## Run, Forest, Run!
2+
3+
### Objective
4+
5+
Learn what restart policies do and how to use them
6+
7+
### Requirements
8+
9+
Make sure Docker is installed on your system and the service is started
10+
11+
```
12+
# Fedora/RHEL/CentOS
13+
rpm -qa | grep docker
14+
systemctl status docker
15+
```
16+
17+
### Instructions
18+
19+
1. Run a container with the following properties:
20+
* image: alpine
21+
* name: forest
22+
* restart policy: always
23+
* command to execute: sleep 15
24+
2. Run `docker container ls` - Is the container running? What about after 15 seconds, is it still running? why?
25+
3. How then can we stop the container from running?
26+
4. Remove the container you've created
27+
5. Run the same container again but this time with `sleep 600` and verify it runs
28+
6. Restart the Docker service. Is the container still running? why?
29+
8. Update the policy to `unless-stopped`
30+
9. Stop the container
31+
10. Restart the Docker service. Is the container running? why?
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
## Running Containers
2+
3+
### Objective
4+
5+
Learn how to run, stop and remove containers
6+
7+
### Requirements
8+
9+
Make sure Podman or Docker (or any other containers engine) is installed on your system
10+
11+
### Instructions
12+
13+
1. Run a container using the latest nginx image
14+
2. List the containers to make sure the container is running
15+
3. Run another container but this time use ubuntu latest and attach to the terminal of the container
16+
4. List again the containers. How many containers are running?
17+
5. Stop the containers
18+
6. Remove the containers
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Sharing Images
2+
3+
## Requirements
4+
5+
Have at least one image locally (run `podman image ls` to confirm).<br>
6+
If you don't have images locally, run simply `podman pull httpd`.
7+
8+
## Objectives
9+
10+
1. Choose an image and create an archive out of it
11+
2. Check the archive size. Is it different than the image size? If yes, what's the difference? If not, why?
12+
3. Copy the generated archive to a remote host
13+
4. Load the image
14+
5. Verify it was loaded and exists on the remote host
15+
16+
## Solution
17+
18+
Click [here to view the solution](solutions/sharing_images.md)

0 commit comments

Comments
 (0)