CLI Flashcards
How to list running containers?
With command docker ps
How to list all containers (running and stopped)?
With command docker ps -a
How to build a Docker image from a Dockerfile?
With command docker build -t image_name .
How to run a Docker container?
With command docker run container_name
How to run a Docker container in the background?
With command docker run -d container_name
How to stop a running Docker container?
With command docker stop container_id
How to start a stopped Docker container?
With command docker start container_id
How to remove a Docker container?
With command docker rm container_id
How to force remove a Docker container?
With command docker rm -f container_id
How to remove a Docker image?
With command docker rmi image_id
How to list all Docker images?
With command docker images
How to pull an image from Docker Hub?
With command docker pull image_name
How to push an image to Docker Hub?
With command docker push image_name
How to tag a Docker image?
With command docker tag source_image target_image
How to execute a command in a running container?
With command docker exec container_id command
How to view logs of a Docker container?
With command docker logs container_id
How to inspect details of a Docker container?
With command docker inspect container_id
How to check the resource usage of Docker containers?
With command docker stats
How to list Docker networks?
With command docker network ls
How to create a Docker network?
With command docker network create network_name
How to connect a container to a network?
With command docker network connect network_name container_id
How to disconnect a container from a network?
With command docker network disconnect network_name container_id
How to list Docker volumes?
With command docker volume ls
How to create a Docker volume?
With command docker volume create volume_name
How to remove a Docker volume?
With command docker volume rm volume_name
How to rename a Docker container?
With command docker rename old_name new_name
How to copy files from host to container?
With command docker cp host_path container_id:container_path
How to copy files from container to host?
With command docker cp container_id:container_path host_path
How to attach to a running Docker container?
With command docker attach container_id
How to stop all running Docker containers?
With command docker stop $(docker ps -q)
How to remove all stopped Docker containers?
With command docker rm $(docker ps -a -q)
How to remove all Docker images?
With command docker rmi $(docker images -q)
How to prune unused Docker objects (containers, images, networks, volumes)?
With command docker system prune
How to prune unused Docker volumes?
With command docker volume prune
How to prune unused Docker networks?
With command docker network prune
How to prune unused Docker images?
With command docker image prune
How to save a Docker image to a tar file?
With command docker save -o file_name.tar image_name
How to load a Docker image from a tar file?
With command docker load -i file_name.tar
How to export a container’s filesystem to a tar file?
With command docker export -o file_name.tar container_id
How to import a container’s filesystem from a tar file?
With command docker import file_name.tar
How to change the restart policy of a Docker container?
With command docker update --restart=policy container_id
How to view the history of a Docker image?
With command docker history image_name
How to log in to a Docker registry?
With command docker login registry_url
How to log out from a Docker registry?
With command docker logout registry_url
How to set environment variables in a Docker container?
With command docker run -e ENV_VAR_NAME=value container_name
How to limit CPU usage of a Docker container?
With command docker run --cpus=number container_name
How to limit memory usage of a Docker container?
With command docker run --memory=amount container_name
How to restart a running Docker container?
With command docker restart container_id
How to run a command in a new container and remove it after execution?
With command docker run --rm container_name command
How to view Docker daemon logs?
With command docker logs container_id
How to list all Docker containers sorted by creation time?
With command docker ps --sort=created
How to list the top processes running inside a Docker container?
With command docker top container_id
How to inspect a Docker image?
With command docker inspect image_name
How to display real-time events from the Docker daemon?
With command docker events
How to show the metadata of a Docker volume?
With command docker volume inspect volume_name
How to create a Docker image from a container’s changes?
With command docker commit container_id new_image_name
How to specify a Dockerfile for building an image?
With command docker build -f Dockerfile .
How to run a container with a specific name?
With command docker run --name container_name image_name