I am following this tutorial .
Docker is the most popular container-runtime.
A container image is a lightweight, standalone, executable package of software that includes everything needed to run an application: code, runtime, system tools, system libraries and settings. Container images become containers at runtime.
Most containers are downloaded from Docker Hub.
sudo apt update sudo apt install curl docker.io -y sudo usermod -aG docker debian newgrp docker
You see that docker is "active", as shown below.sudo systemctl status docker
Press Q to exit this message.
The message shows that Docker is running correctly, as shown below.docker run hello-world
https://hub.docker.com/_/hello-worldYou can see the Dockerfile for this image here. It contains only three lines, as shown below.
The commands "FROM", "COPY", and "CMD" are explained here.FROM scratch COPY hello / CMD ["/hello"]
Here is an explanation of each command:
The source code for the hello program is here. It just prints out a message and exits.
FROM scratch FROM specifies the base image.
FROM scratch means to use the host kernel, without adding any new files or folders to it.COPY hello / Copies the hello executable to the root of the container.
This executable is statically compiled, so it doesn't need any library files to run.CMD ["/hello"] Executes the "hello" command.
You see the kernel version of your host system, and the first ten running processes, as shown below.uname -r ps aux | head -n 10
Here is an explanation of each command:docker run -it busybox uname -r ps aux exit docker ps docker ps -a
Notice that the kernel version inside the container is the same as the host kernel version--docker shares the kernel with the host. Docker containers are less isolated from the host system than virtual machine are, which makes them smaller.
docker run -it busybox Download the "busybox" container and run it in interactive mode uname -r Show the kernel version inside the container ps aux Show running processes inside the container exit Exit the container and stop it docker ps List running containers docker ps -a List all containers
There are very few processes inside the container.
Notice the name of your container, highlighted in the image below.
To exit the container without stopping it, press these keystrokes:docker container start cool_hodgkin docker exec -it cool_hodgkin sh ps aux
Ctrl+p, Ctrl+q
Execute this command to see running containers:
Your container is still running, as shown below.docker ps
Your container is gone, as shown below.docker ps -a docker container stop cool_hodgkin docker system prune y docker ps -a
This server simply repeats back any HTTP requests sent to it.
On your Linux server, execute this command:
The container downloads and runs, and announces that it is running on port 80, as shown below.docker run ealen/echo-server
You don't have a new $ prompt, because this container is running in attached mode--stdin, stdout, and stderr are connected to your terminal.
Open a second Terminal or SSH window onto your host system.
In the second Terminal, execute these commands:
The echo-server container is running, but not listening on any ports, as shown below.docker ps sudo ss -pantl
Notice the container's name, highlighted in the image below.
Execute this command to stop the echo-server, replacing the name with the correct name for your container.
docker stop relaxed_boyd
Note these options for the "docker run" command:docker run --detach --publish 8080:80 --name echosrv1 ealen/echo-server docker ps curl localhost:8080
The container runs, and the host starts listening on port 8080.
--detach Run container in the background --publish 8080:80 Forward host port 8080 to container port 80 --name echosrv1 Assign the container the name "echosrv1"
An HTTP request to that port echoes back, as shown below.
Flag H 150.1: Inside the Echo Server (10 pts)
On your Linux server, execute these commands, to open an interactive shell on the running echo server and look inside it.The flag is covered by a green rectangle in the image below.docker exec -it echosrv1 sh ls -l ps a netstat -pant exit
Your container is gone, as shown below.docker stop echosrv1 docker ps -a docker system prune y docker ps -a
On your Linux server, execute this command.
Log in again and open a Terminal or SSH session.sudo reboot
The curl command fetches a default nginx page, as shown below.docker run --detach --publish 8080:80 --name webserver1 nginx docker ps curl localhost:8080
Now the curl command retrieves the text you placed inside the container, as shown below.docker exec -it webserver1 sh echo "INSIDE THE CONTAINER" > /usr/share/nginx/html/index.html exit curl localhost:8080
On your Linux server, execute these commands.
The curl command fetches date from the host system, as shown below.cd mkdir html echo "ON HOST SYSTEM" > html/index.html docker stop webserver1 docker run --detach --volume ~/html:/usr/share/nginx/html --publish 8080:80 --name webserver2 nginx docker ps curl localhost:8080
The container is not running, and there is no process listening on port 3306, as shown below.docker run --detach --publish 3306:3306 --name db1 mysql docker ps sudo ss -pantl
Something is wrong.
It requires an environment variable specifying the MYSQL_ROOT_PASSWORD.
On your Linux server, execute these commands.
Now the container is running, and listening on port 3306, as shown below.docker rm db1 docker run --detach --env MYSQL_ROOT_PASSWORD=my-secret-pw --publish 3306:3306 --name db2 mysql docker ps sudo ss -pantl
Flag H 150.2: Inside the MySQL Server (10 pts)
On your Linux server, execute these commands, to open an interactive shell on the running MySQL server and look inside it.The flag is covered by a green rectangle in the image below.docker exec -it db2 sh ls exit
Posted 3-8-25
Video added 3-11-25