Welcome to "A Guide to key commands in Docker"! In this post, we're going to simplify some key concepts and commands that you need to know to start working with Docker, one of the most popular containerization platforms.
What is Docker? π³
Docker is a platform that enables developers to package applications into containers standardized executable components combining application source code with the operating system (OS) libraries and dependencies required to run that code in any environment.
Basic Docker Commands: π‘
Docker Run:
docker run <image_name>
: This is the command you'll use to start a new container from an image.
Overriding Default Commands:
You can override the default command set in the Docker image by appending a new command after the image name:
docker run <image_name> <command>
Listing Running Containers:
- To see the currently running containers, use
docker ps
. For a list that includes stopped containers, add the--all
flag:docker ps --all
.
- To see the currently running containers, use
Container Lifecycle:
docker create <image_name>
followed bydocker start <container_id>
can be used as a two-step alternative todocker run
.
Removing Containers:
docker system prune
: This command removes all stopped containers and other unused objects like dangling images and unused networks.
Container Interaction: π€
Stopping Containers:
docker stop <container_id>
: Gracefully stops a running container.
Executing Commands in Running Containers:
docker exec -it <container_id> <command>
: Lets you run additional commands in running containers.
The
-it
Flag:- This flag is short for
--interactive
+--tty
. It allows you to interact with the container via a terminal interface.
- This flag is short for
Advanced Docker Commands: π
Docker Logs:
- To retrieve the logs of a container, use
docker logs <container_id>
.
- To retrieve the logs of a container, use
Docker Kill:
- Use
docker kill <container_id>
to force stop a running container.
- Use
Conclusion:
There you have it, a starter on some of the basic yet crucial Docker commands and their purpose. Remember, practice makes perfect.
The more you use these commands, the more comfortable you'll become with the Docker environment.
Stay tuned for more blogs on Docker and containerization! π’