Docker Container Attachment Adventure

DockerDockerBeginner
Practice Now

Introduction

In this lab, we'll immerse ourselves in the captivating world of the Ming Dynasty palace, where the Emperor needs our assistance. The scenario will feature the majestic Ming Dynasty palace and the revered Emperor, offering an opportunity to understand the concept of Docker attach in a creative setting.

Scene Description

The magnificent Ming Dynasty palace stands as a testament to China’s rich history and culture. Within its opulent halls, the Emperor diligently oversees the affairs of his empire. The Emperor, a wise and scholarly figure, is seeking our expertise to assist in managing the affairs of the kingdom through the advanced technology of Docker containers.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL docker(("`Docker`")) -.-> docker/ContainerOperationsGroup(["`Container Operations`"]) docker/ContainerOperationsGroup -.-> docker/attach("`Attach to Container`") subgraph Lab Skills docker/attach -.-> lab-268693{{"`Docker Container Attachment Adventure`"}} end

Prepare the Palace Gardens

In this step, we need to create a serene environment in the palace gardens. The Emperor seeks a place of tranquility to contemplate the kingdom's future. The step involves setting up a Docker container using an official image and ensuring it functions as intended.

  1. Create a file named garden.html in the ~/project directory with following lines:

    <h1>Tranquil Garden</h1>
  2. Use the nginx Docker image to launch a container and serve the garden.html file.

    docker run -d -p 8080:80 --name garden-container -v ~/project:/usr/share/nginx/html nginx
  3. Add a web service mapping from the top menu lab and set the port mapping. If the Nginx web server is running successfully, the lab environment will automate navigating to a random URL in the server lab. Visit the random URL with /garden.html in web service tab to verify that the garden page is accesible.

Audience with the Emperor

In this step, we'll prepare to meet the Emperor in the Throne Room. We'll create a new Docker container and configure it to run a simple interactive application so that we can communicate with the Emperor directly.

  1. Create a file named audience.py in the ~/project directory with following lines:
    print("Hello Docker!")
  2. Use the python Docker image to launch a container and run the audience.py file in interactive mode.
    docker run -it --name audience-container -v ~/project:/usr/src/app python python /usr/src/app/audience.py

Summary

In this lab, we embarked on an immersive journey into the world of Docker containers through an enthralling Ming Dynasty palace scenario. By stepping into the shoes of an assistant to the Emperor, we gained practical experience in utilizing Docker attach to manage various aspects of the empire, from creating peaceful garden environments to engaging in direct communication with the revered Emperor. Through this experience, we deepened our understanding of Docker's attach functionality and its applications in real-world scenarios.

Other Docker Tutorials you may like