Update
This commit is contained in:
31
exercises/containers/run_forest_run.md
Normal file
31
exercises/containers/run_forest_run.md
Normal file
@ -0,0 +1,31 @@
|
||||
## Run, Forest, Run!
|
||||
|
||||
### Objective
|
||||
|
||||
Learn what restart policies do and how to use them
|
||||
|
||||
### Requirements
|
||||
|
||||
Make sure Docker is installed on your system and the service is started
|
||||
|
||||
```
|
||||
# Fedora/RHEL/CentOS
|
||||
rpm -qa | grep docker
|
||||
systemctl status docker
|
||||
```
|
||||
|
||||
### Instructions
|
||||
|
||||
1. Run a container with the following properties:
|
||||
* image: alpine
|
||||
* name: forest
|
||||
* restart policy: always
|
||||
* command to execute: sleep 15
|
||||
2. Run `docker container ls` - Is the container running? What about after 15 seconds, is it still running? why?
|
||||
3. How then can we stop the container from running?
|
||||
4. Remove the container you've created
|
||||
5. Run the same container again but this time with `sleep 600` and verify it runs
|
||||
6. Restart the Docker service. Is the container still running? why?
|
||||
8. Update the policy to `unless-stopped`
|
||||
9. Stop the container
|
||||
10. Restart the Docker service. Is the container running? why?
|
71
exercises/containers/solutions/run_forest_run.md
Normal file
71
exercises/containers/solutions/run_forest_run.md
Normal file
@ -0,0 +1,71 @@
|
||||
## Run, Forest, Run!
|
||||
|
||||
### Objective
|
||||
|
||||
Learn what restart policies do and how to use them
|
||||
|
||||
### Requirements
|
||||
|
||||
Make sure Docker is installed on your system and the service is started
|
||||
|
||||
```
|
||||
# Fedora/RHEL/CentOS
|
||||
rpm -qa | grep docker
|
||||
systemctl status docker
|
||||
```
|
||||
|
||||
### Instructions
|
||||
|
||||
1. Run a container with the following properties:
|
||||
* image: alpine
|
||||
* name: forest
|
||||
* restart policy: always
|
||||
* command to execute: sleep 15
|
||||
|
||||
`docker run --restart always --name forest alpine sleep 15`
|
||||
|
||||
2. Run `docker container ls` - Is the container running? What about after 15 seconds, is it still running? why?
|
||||
|
||||
|
||||
It runs even after it completes to run `sleep 15` because the restart policy is "always". This means that Docker will keep restarting the **same** container even after it exists.
|
||||
|
||||
|
||||
3. How then can we stop the container from running?
|
||||
|
||||
The restart policy doesn't apply when the container is stopped with the command `docker container stop`
|
||||
|
||||
4. Remove the container you've created
|
||||
|
||||
```
|
||||
docker container stop forest
|
||||
docker container rm forest
|
||||
```
|
||||
|
||||
5. Run the same container again but this time with `sleep 600` and verify it runs
|
||||
|
||||
```
|
||||
docker run --restart always --name forest alpine sleep 600
|
||||
docker container ls
|
||||
```
|
||||
|
||||
6. Restart the Docker service. Is the container still running? why?
|
||||
|
||||
```
|
||||
sudo systemctl restart docker
|
||||
```
|
||||
Yes, it's still running due to the restart policy `always` which means Docker will always bring up the container after it exists or stopped (not with the stop command).
|
||||
|
||||
8. Update the policy to `unless-stopped`
|
||||
|
||||
`docker update --restart unless-stopped forest`
|
||||
|
||||
9. Stop the container
|
||||
|
||||
`docker container stop forest`
|
||||
|
||||
10. Restart the Docker service. Is the container running? why?
|
||||
|
||||
```
|
||||
sudo systemctl restart docker
|
||||
```
|
||||
No, the container is not running. This is because we changed the policy to `unless-stopped` which will run the container unless it was in stopped status. Since before the restart we stopped the container, Docker didn't continue running it after the restart.
|
23
exercises/devops/containerize_app.md
Normal file
23
exercises/devops/containerize_app.md
Normal file
@ -0,0 +1,23 @@
|
||||
## Containerize an Application
|
||||
|
||||
1. Clone an open source project you would like to containerize. A couple of suggestions:
|
||||
|
||||
```
|
||||
https://github.com/bregman-arie/node-hello-world
|
||||
https://github.com/bregman-arie/flask-hello-world
|
||||
```
|
||||
|
||||
`git clone https://github.com/bregman-arie/node-hello-world`
|
||||
|
||||
2. Write a Dockerfile you'll use for building an image of the application (you can use any base image you would like)
|
||||
|
||||
```
|
||||
FROM alpine
|
||||
LABEL maintainer="your name/email"
|
||||
RUN apk add --update nodejs nodejs-npm
|
||||
COPY . /src
|
||||
WORKDIR /src
|
||||
RUN npm install
|
||||
EXPOSE 8080
|
||||
ENTRYPOINT ["node", "./app.js"]
|
||||
```
|
Reference in New Issue
Block a user