Why Manage Containers?
Once your containers are running, you’ll often need to inspect, monitor, or jump inside them to see what’s happening. Docker provides several powerful CLI tools to help you interact with containers just like you would with regular servers.
Getting Help
Whenever you forget a command or need to explore options, Docker has a built-in help system:
docker --help
docker helpBoth commands will show a list of available subcommands, descriptions, and usage examples — a great built-in manual when you’re experimenting with the CLI.
Starting the "Nginx" Container
The official nginx image from Docker Hub makes it easy to run a lightweight web server. You can use it to test deployments or serve static content locally.
docker run -d -p 3000:80 library/nginx:latestThe -d flag runs it in the background (detached mode), and -p maps port 80 inside the container to port 3000 on your local machine.
Once started, check if it’s running:
docker psYou should see the container listed, showing the image name, container ID, and exposed ports.
Open your browser and visit http://localhost:3000 — it should display the default Nginx welcome page.
Running Commands Inside a Container
Containers are isolated environments — but you can still interact with them directly. The docker exec command lets you run commands inside an already running container:
docker exec CONTAINER_ID lsThat lists files inside the container’s working directory. You can even create new files or logs:
docker exec CONTAINER_ID touch test.log
docker exec CONTAINER_ID lsYou’ll now see test.log appear inside the container. It’s a quick and safe way to experiment without restarting anything.
Inspecting What’s Running Inside
Wondering what web server is powering that container? You can check which processes are listening on which ports using:
docker exec CONTAINER_ID netstat -ltnpYou’ll notice that something (usually nginx) is bound to port 80 — that’s the process serving the webpage you saw earlier.
Opening an Interactive Shell
If you want to explore deeper, you can open a live shell session inside the container using docker exec with two special flags:
- -i → keeps input open for interaction
- -t → allocates a terminal (TTY)
docker exec -it CONTAINER_ID /bin/shThis feels like SSH — you’re now “inside” the container’s terminal environment.
Try navigating into the folder where the web content lives:
cd /usr/share/nginx/htmlThis directory holds the files that are served by the nginx web server. You can modify them live. For example:
echo "Hello from inside Docker!" > index.htmlNow refresh http://localhost:3000 — you should see your custom message! When done, exit with:
exitKey Takeaways
docker helpshows available commandsdocker run -d -p 3000:80 library/nginx:latestruns a test containerdocker pslists active containersdocker execlets you run commands or open a live shellnetstathelps inspect what’s running inside- You can safely modify files inside a container in real time — great for learning or debugging