Commands
Container Management
List running containers:
docker ps
List all containers (running and stopped):
docker ps -a
Start a container:
docker start [CONTAINER_NAME/CONTAINER_ID]
Stop a container:
docker stop [CONTAINER_NAME/CONTAINER_ID]
Restart a container:
docker restart [CONTAINER_NAME/CONTAINER_ID]
Remove a container:
docker rm [CONTAINER_NAME/CONTAINER_ID]
Pause a container:
docker pause [CONTAINER_NAME/CONTAINER_ID]
Unpause a container:
docker unpause [CONTAINER_NAME/CONTAINER_ID]
Inspect a container:
docker inspect [CONTAINER_NAME/CONTAINER_ID]
Image Management
List local Docker images:
docker images
Download a Docker image:
docker pull [IMAGE_NAME]
Create a Docker image from a Dockerfile:
docker build -t [IMAGE_NAME] [DOCKERFILE_PATH]
Remove a Docker image:
docker rmi [IMAGE_NAME/IMAGE_ID]
Tag a Docker image:
docker tag [IMAGE_NAME/IMAGE_ID] [REPOSITORY_NAME]:[TAG]
Push a Docker image to a repository:
docker push [REPOSITORY_NAME]:[TAG]
Pull a Docker image from a repository:
docker pull [REPOSITORY_NAME]:[TAG]
Networking
List Docker networks:
docker network ls
Create a Docker network:
docker network create [NETWORK_NAME]
Connect a container to a network:
docker network connect [NETWORK_NAME] [CONTAINER_NAME/CONTAINER_ID]
Disconnect a container from a network:
docker network disconnect [NETWORK_NAME] [CONTAINER_NAME/CONTAINER_ID]
Volume Management
List Docker volumes:
docker volume ls
Create a Docker volume:
docker volume create [VOLUME_NAME]
Remove a Docker volume:
docker volume rm [VOLUME_NAME]
Attach a volume to a container:
docker run -v [VOLUME_NAME]:[CONTAINER_PATH] [IMAGE_NAME]
Inspect a volume:
docker volume inspect [VOLUME_NAME]
Miscellaneous
Open a shell inside a running container:
docker exec -it [CONTAINER_NAME/CONTAINER_ID] sh
View logs of a running container:
docker logs -f [CONTAINER_NAME/CONTAINER_ID]
Last updated