1- Docker Run
The docker run command is your gateway to launching containers from Docker images. It allows you to specify image names, options, and runtime configurations.
docker run -d -p 8080:80 nginx
-d: Run the container in detached mode (in the background).
-p: Map ports from the host to the container.
2- Docker Pull
Before running a container, you often need to download the Docker image from a registry like Docker Hub. The docker pull command accomplishes this.
docker pull ubuntu:latest
3- Docker PS
To view the list of running containers, you use the docker ps command. It provides information about container IDs, names, status, and ports. To see all containers, including stopped ones, you can use docker ps -a.
docker ps
4- Docker Stop and Docker Start
These two commands allow you to control the state of a container. docker stop halts a running container, while docker start resumes a stopped one.
docker stop {container_name_or_id}
docker start {container_name_or_id}
5- Docker Logs
The docker logs command is invaluable for troubleshooting and monitoring. It retrieves the logs generated by a container
docker logs {container_name_or_id}
6- Docker Exec
You can execute commands inside a running container using docker exec. This is particularly useful for debugging or running administrative tasks.
docker exec -it {container_name_or_id} {bash}
-it: Interactive mode with a terminal.
bash: The shell you want to use inside the container.
7- Docker Build
When you need to create a custom Docker image, the docker build command is your friend. It uses a Dockerfile to define image instructions.
docker build -t custom_image_name .
8- Docker Images
To list locally available Docker images, use docker images. This command displays image names, sizes, and tags.
docker images
9- Docker RMI
Removing Docker images that are no longer needed frees up disk space. docker rmi allows you to remove images by their name or ID.
docker rmi image_name_or_id
10- Docker Network
Docker provides a networking feature to connect containers and services. The docker network command helps manage these networks.
docker network ls
docker network create my_network
Top comments (3)
There are also some I'm using quite often:
docker system prune
Remove all unused containers, networks, images (both dangling and unreferenced), and optionally, volumes.
or
--all
flag, for example withdocker ps --all
Show all the containers, default is only running containers
yea sure
amazing article keep going