Medieval Farmers Docker Adventure

DockerDockerBeginner
Practice Now

Introduction

In this lab, you will be transported to a medieval city where a farmer needs your assistance. The city is bustling with activity, and the farmer needs a way to transport his goods efficiently to various parts of the city. Your goal is to attach to the farmer's transport container and oversee the logistics of moving the goods to different locations within the city.

This is a Guided Lab, which provides step-by-step instructions to help you learn and practice. Follow the instructions carefully to complete each step and gain hands-on experience. Historical data shows that this is a beginner level lab with a 97% completion rate. It has received a 91% positive review rate from learners.

Create a Docker Container

In this step, you will create a Docker container to represent the farmer's transport container.

## Create a new Docker container
docker run --name transport-container -d alpine tail -f /dev/null

Attach to the Container

Now, attach to the transport container to observe the logistics.

## Attach to the container
docker attach transport-container

Note: To safely detach from the container without stopping it, press Ctrl-p followed by Ctrl-q. If you use Ctrl-c, it will stop the container process.

Transfer Goods

In this step, use the following command in another terminal to take an interactive shell to the container, and simulate the transfer of goods inside the attached container.

docker exec -it transport-container sh
## create a hello.py file
echo "print('Hello Docker')" > hello.py
## Inside the attached container, move the hello.py to different locations
mv hello.py /var

Summary

In this lab, you learned how to use the Docker attach command to interact with a running container. By simulating a medieval city scenario, you were able to grasp the concept of attaching to a container and executing operations within it. This hands-on experience provides a practical understanding of container management and attachment techniques.