docker images
Description: Lists all Docker images on your local system.
docker pull <image_name>:<tag>
Description: Downloads an image from a Docker registry. For example:
docker pull ubuntu:latest
docker build -t <image_name>:<tag> <path_to_dockerfile>
Description: Builds an image from a Dockerfile. For example:
docker build -t myapp:1.0 .
docker tag <source_image>:<source_tag> <destination_image>:<destination_tag>
Description: Tags an image with a new name and tag. For example:
docker tag myapp:1.0 myrepo/myapp:latest
docker rmi <image_name>:<tag>
Description: Removes an image from the local system. For example:
docker rmi myapp:1.0
docker ps
Description: Lists all running containers. Use docker ps -a
to list all containers, including stopped ones. For example:
docker ps
docker run [OPTIONS] <image_name>:<tag>
Description: Creates and starts a new container. For example:
docker run -d -p 80:80 nginx
docker stop <container_id>
Description: Stops a running container. For example:
docker stop 123456
docker start <container_id>
Description: Starts a stopped container. For example:
docker start 123456
docker restart <container_id>
Description: Restarts a running or stopped container. For example:
docker restart 123456
docker rm <container_id>
Description: Removes a container from the local system. For example:
docker rm 123456
docker exec -it <container_id> <command>
Description: Runs a command in a running container. For example:
docker exec -it 123456 bash
docker cp <container_id>:<source_path> <destination_path>
docker cp <source_path> <container_id>:<destination_path>
Description: Copies files between a container and the local filesystem. For example:
docker cp 123456:/app/config.json ./config.json
docker cp ./app/config.json 123456:/app/config.json
docker network ls
Description: Lists all Docker networks. For example:
docker network ls
docker network create <network_name>
Description: Creates a new Docker network. For example:
docker network create mynetwork
docker network connect <network_name> <container_id>
Description: Connects a container to a network. For example:
docker network connect mynetwork 123456
docker network disconnect <network_name> <container_id>
Description: Disconnects a container from a network. For example:
docker network disconnect mynetwork 123456
docker volume ls
Description: Lists all Docker volumes. For example:
docker volume ls
docker volume create <volume_name>
Description: Creates a new Docker volume. For example:
docker volume create myvolume
docker volume inspect <volume_name>
Description: Displays detailed information about a volume. For example:
docker volume inspect myvolume
docker volume rm <volume_name>
Description: Removes a volume from the local system. For example:
docker volume rm myvolume
docker system prune
Description: Removes all stopped containers, unused networks, dangling images, and build cache. Use with caution!For example:
docker system prune
docker image prune
Description: Removes unused images. For example:
docker image prune
docker container prune
Description: Removes stopped containers. For example:
docker container prune
docker volume prune
Description: Removes unused volumes. For example:
docker volume prune
docker logs <container_id>
Description: Displays logs from a container. For example:
docker logs 123456
docker-compose up -d
Description: Creates and starts containers as defined in the docker-compose.yml
file. For example:
docker-compose up -d
docker-compose down
Description: Stops and removes all containers defined in the docker-compose.yml
file. For example:
docker-compose down
docker-compose logs
Description: Shows logs from all services in the stack. For example:
docker-compose logs
To streamline your workflow, consider adding these aliases to your shell configuration file (.bashrc
, .zshrc
, etc.):
alias dps='docker ps'
alias dpsa='docker ps -a'
alias drm='docker rm -f'
alias di='docker images'
alias dimg='docker image prune -a'
alias dcont='docker container prune'
alias dvol='docker volume prune'
Docker commands are essential tools for managing containers, images, networks, and volumes. Understanding and using these commands effectively will help you streamline your development and deployment workflows. For more detailed information, refer to the Docker Documentation.