So you're venturing into the realm of Docker? Great choice! This technology is a game changer for developers, making it incredibly simple to package and run apps in containers.
To help you started, here are some important Docker commands you'll commonly use.
1. Installing Docker
Before you start, make sure Docker is installed on your machine. You can follow the official installation guide for Docker Desktop.
2. Basic Docker Commands
docker --version
This command verifies your Docker installation by checking the installed version.
docker pull <image_name>
This command pulls a Docker image from the Docker Hub repository.
docker run <image_name>
This command creates and runs a container from a Docker image. To run container in detached mode add -d
flag.
To map container port to local ports add -p
flag.
Example:
docker run -d -p 8080:80 nginx
This runs nginx container in port 8080 in detached mode(Runs in background i.e. No terminal will be tied to it).(We are mapping container port 80 to our local port 8080)
docker ps
This shows all running containers. Use docker ps -a to see all containers, including those that are stopped.
docker images
This command lists all Docker images downloaded to your local machine.
3. Commands to Manage Containers
docker stop <container_id>
This command stops a running container.
docker start <container_id>
This command starts a stopped container.
docker logs <container_id>
This command is used to show logs of a running container.
docker restart <container_id>
This command restarts a running container.
docker rm <container_id>
This command deletes a stopped container. Use -f
to force remove a running container.
(You can replace with the actual container ID or name.)
docker rmi <image_name>
This command deletes an image from local machine. Used to free up space.
docker system prune
This command cleans up all stopped containers, dangling images, and unused networks.
Docker makes it easy to package and deploy applications. If you master these commands, it will give you a solid foundation as you begin exploring more advanced features. Any questions ask them below.
Happy Dockerizing!
Top comments (4)
Nice π
Insightful post!
Thanks for the blog
Greatπ