CloudProg W04IST-SI4527G Lab03
CloudProg W04IST-SI4527G Lab03
1 Learning goals
1. Running simple containers.
2. Create container image.
3. Run container from the image.
4. Orchestrate multiple containers.
2 Prerequisites
1. Create new or start your Cloud9 environment.
2. Open the EC2 instance related to your Cloud9 environment. Check if Security group assigned
to this instance allows for incoming TCP traffic on ports 8080 and 8081 from any IPv4 address.
If not – readjust the Security group.
3. In Cloud9 open the second Terminal (you can press Alt-T).
3 Exercises
3.1 Running containers
In the first part, you will start containers with different Linux distributions: Debian, Fedora, Alpine.
For each distribution you install stress-ng application. You will also save one of the modified
containers as an image, to create new containers using this modified image.
1. Check the version and configuration of Docker using command: docker version
2. Start the container using Debian image: docker run -it debian /bin/bash . Pay atten-
tion, how long does container start.
3. Execute the following commands and observe the results:
hostname
cat /etc/os-release
apt update
apt install stress-ng
echo "Hello" > myfile.txt
cat myfile.txt
4. In the second terminal execute command: docker ps . Compare the ContainerID and the
result of the hostname . What is the name of the container?
1
5. In the first terminal (debian) type exit
6. Execute again docker ps . Can you see your container? Execute: docker ps -a . Can
you see your container now?
7. Execute: docker start -ai e80f (replace e80f with your ID). When inside container
execute: cat myfile.txt .
12. Execute command docker run -it alpine /bin/sh . Execute all commands from step 3.
Were you successful? Try apk update then apk add stress-ng . Exit from the container.
13. List all container images stored in your machine: docker image ls . Compare sizes of
images.
2. In the my-site folder create index.html file, and put at least your name inside.
3. Start new container with Apache webserver:
Option -v mount folder from your system into containers folder. Option -p publishes
containers private port (8080) to port on your machine (8081). Option --name gives your
container a constant name, instead of random name assigned by Docker.
4. Open your browser and connect to port 8081 using Cloud9 / EC2 instance public address.
5. Modify index.html and refresh the browser. Can you see the changes?
Pay attention that every time you reload the page you can see log information in the terminal.
6. In Terminal window press Ctrl-C to stop the Apache container.
7. Now run the container in the background. When you use -d option, container runs in the
background, so you can still use the terminal.
2
docker run --name apache -d -v /home/ec2-user/environment/my-site:/app
↪ -p 8081:8080 bitnami/apache
If you cannot start a new container, because of the name, remove the old one from the
memory: docker rm apache .
3
13. Repeat the same steps to build container for frontend. Compare the content of both
Dockerfile . Especially pay attention to the first line FROM .
Warning: Do not forget to put IP address of your EC2 instance inside src/index.html file.
14. Verify if frontend displays information from backend.
Warning: The second command curl contains very long URL address. Copy it into text
editor and join it into one long line. Then paste in into bash terminal.
4. Run command docker compose up -d to start both backend and frontend.
5. List all running containers.
6. Open frontend and backend in the browser.
7. Stop all modules with command docker compose down