top of page
Writer's picturevP

Running Containers - Day 41

Welcome back to #90DaysOfDevOps! Today, we're taking the next step in our Docker journey - running containers. Containers are where the real action happens. They are your applications, encapsulated and ready to perform. We'll explore running containers, understand the nitty-gritty of foreground and background processes, and get comfortable with some essential container management commands.


Unboxing Running Containers

Running Containers in the Foreground

When you run a container, you can choose to run it in the foreground, which means the container's output is visible in your terminal. For example, when you ran your first Docker container, you used the -d flag to run it in detached mode. Without it, the container would run in the foreground, and you'd see its logs in your terminal.

Here's a quick recap:

docker run -p 80:80 nginx

This command starts an Nginx web server container in the foreground, listening on port 80 of your host machine.


Running Containers in the Background

Running containers in the background means they won't hog your terminal. You can continue using your terminal for other tasks without being tied to the container's logs. To run a container in the background, use the -d flag:

docker run -d -p 80:80 nginx

This command runs an Nginx container in the background.


Managing Containers

docker ps - List Your Containers

To see a list of your running containers, use the docker ps command:

docker ps

This command displays the running containers along with essential information like container IDs, names, ports, and status.


Starting, Stopping, and Restarting Containers

If you want to start, stop, or restart a container, you'll use the docker start, docker stop, and docker restart commands. Simply specify the container's name or ID after the command.

1. Starting a stopped container:

docker start my-container 

2. Stopping a running container:

docker stop my-container 

3. Restarting a container:

docker restart my-container 

This management trifecta gives you full control over your containers. You can gracefully stop and start them, and even restart if they run into any hiccups.


Running containers is where the real magic of Docker happens. You've learned how to run containers in the foreground and background, allowing you to choose the level of interaction you want. And by mastering commands like docker ps, docker start, docker stop, and docker restart, you have the keys to container management.


As we journey deeper into DevOps, remember that effective container management is essential for keeping your applications running smoothly. Stay tuned for more container adventures in the days to come.


Thank you for reading!


*** Explore | Share | Grow ***

12 views0 comments

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating
bottom of page