run
, ps
, stop
, rm
, images
, and logs
This blog post provides a detailed guide to understanding and using basic Docker commands. These commands are essential for managing containers and images effectively.
docker run
The docker run
command creates and starts a new container from a specified image. It's the most fundamental command in Docker.
docker run [OPTIONS] IMAGE [COMMAND] [ARG...]
Here's a breakdown:
-p
), volume mounts (-v
), and interactive mode (-it
).Example:
docker run -d -p 80:80 nginx
This command runs an Nginx web server in detached mode (-d
), mapping port 80 on the host to port 80 in the container.
docker ps
The docker ps
command lists running containers. Use the -a
flag to show all containers, including stopped ones.
docker ps [OPTIONS]
Example:
docker ps -a
docker stop
The docker stop
command stops a running container gracefully by sending a SIGTERM signal.
docker stop CONTAINER_ID
Example:
docker stop a1b2c3d4e5f6
docker rm
The docker rm
command removes a stopped container.
docker rm CONTAINER_ID
Example:
docker rm a1b2c3d4e5f6
docker images
The docker images
command lists locally stored images.
docker images [OPTIONS]
Example:
docker images
docker logs
The docker logs
command fetches the logs of a container.
docker logs [OPTIONS] CONTAINER_ID
Example:
docker logs a1b2c3d4e5f6
These basic Docker commands are crucial for building, running, and managing containers. Understanding their usage is a cornerstone of efficient Docker workflows. This blog post has provided a detailed look at each command, equipping you with the knowledge to manage your containers effectively. Explore the Docker documentation for more advanced usage and options.