0
0
Dockerdevops~30 mins

Executing commands with docker exec - Mini Project: Build & Apply

Choose your learning style9 modes available
Executing commands with docker exec
📖 Scenario: You are managing a Docker container running a simple web server. You want to check the server's status and list files inside the container without stopping it.
🎯 Goal: Learn how to use docker exec to run commands inside a running container.
📋 What You'll Learn
Use docker exec to run commands inside a container
Identify the container by its name
Run simple commands like ls and cat inside the container
💡 Why This Matters
🌍 Real World
In real life, developers and system admins often need to check or fix things inside running containers without stopping them. Using <code>docker exec</code> lets you do that safely.
💼 Career
Knowing how to use <code>docker exec</code> is essential for troubleshooting, monitoring, and managing Docker containers in development and production environments.
Progress0 / 4 steps
1
Create and run a container named webserver
Run a Docker container named webserver using the nginx image in detached mode.
Docker
Need a hint?

Use docker run -d --name webserver nginx to start the container in the background.

2
Set a variable with the container name
Create a shell variable called container and set it to the string webserver.
Docker
Need a hint?

Use container=webserver to store the container name in a variable.

3
List files inside the container's /usr/share/nginx/html directory
Use docker exec with the variable container to run ls /usr/share/nginx/html inside the container.
Docker
Need a hint?

Use docker exec $container ls /usr/share/nginx/html to list files inside the container.

4
Display the content of the index.html file inside the container
Use docker exec with the variable container to run cat /usr/share/nginx/html/index.html inside the container and print the output.
Docker
Need a hint?

Use docker exec $container cat /usr/share/nginx/html/index.html to show the file content.