Basic Container Operations
Run a Container
docker run -it ubuntu
Starts a new interactive container using the Ubuntu image.
Build an Image
docker build -t my-custom-image:latest .
Creates a custom Docker image named 'my-custom-image' from the current directory.
Pull an Image
docker pull nginx:latest
Downloads the latest version of the Nginx image from the Docker Hub.
Push an Image
docker push my-custom-image:latest
Uploads the custom image 'my-custom-image' to a Docker registry.
List Images
docker images
Displays a list of locally available Docker images.
Container Lifecycle Management
Stop a Container
docker stop my_container
Gracefully stops the running container 'my_container'.
Start a Container
docker start my_container
Resumes execution of the stopped container 'my_container'.
Restart a Container
docker restart my_container
Stops and then starts the container 'my_container'.
Kill a Container
docker kill -s SIGTERM my_container
Sends a termination signal to forcefully stop the running container 'my_container'.
Remove a Container
docker rm my_container
Deletes the container 'my_container'.
Image Management
Remove an Image
docker rmi my-custom-image:latest
Deletes the image 'my-custom-image' with the latest tag.
Create Image from Changes
docker commit my_container my-custom-image:latest
Creates a new image 'my-custom-image' from changes made in a running container 'my_container'.
Save Images to Archive
docker save -o my-images.tar.gz my-custom-image:latest
Saves the image 'my-custom-image' with the latest tag to a tar archive.
Load Image from Archive
docker load -i my-images.tar.gz
Loads an image from the tar archive 'my-images.tar.gz'.
Container Interaction
Execute Command in Container
docker exec -it my_container bash
Runs an interactive bash shell in the running container 'my_container'.
Fetch Container Logs
docker logs my_container
Retrieves and displays the logs of the container 'my_container'.
Inspect Container or Image
docker inspect my_container
Retrieves detailed information about the container 'my_container'.
Copy Files Between Container and Host
docker cp my_container:/path/in/container /path/on/host
Copies files or folders between the container 'my_container' and the local filesystem.
System Cleanup and Maintenance
Remove Unused Resources
docker system prune
Cleans up stopped containers, dangling images, and unused networks and volumes.
Miscellaneous Commands
List Port Mappings
docker port my_container
Shows the port mappings of the container 'my_container'.
Display Running Processes
docker top my_container
Lists the running processes inside the container 'my_container'.
Manage Volumes
docker volume ls
Lists the Docker volumes on the host.
Show Docker Version
docker version
Displays information about the installed Docker version.
Show Changes in Container Filesystem
docker diff my_container
Shows the filesystem changes made in the container 'my_container'.
Export Container Filesystem
docker export my_container > my_container_exported.tar
Exports the filesystem of the container 'my_container' to a tar archive.
Import Filesystem to Create Image
docker import my_container_exported.tar my-imported-image:latest
Imports the filesystem from the tar archive 'my_container_exported.tar' to create a new image 'my-imported-image' with the latest tag.
Docker Network Commands
List Docker Networks
docker network ls
Displays a list of Docker networks.
Create a Docker Network
docker network create my_network
Creates a new Docker network named 'my_network'.
Inspect Docker Network
docker network inspect my_network
Retrieves detailed information about the Docker network 'my_network'.
Docker Registry Commands
Docker Login
docker login
Logs in to a Docker registry.
Docker Logout
docker logout
Logs out from a Docker registry.
Docker Volume Commands
Create a Docker Volume
docker volume create my_volume
Creates a new Docker volume named 'my_volume'.
Inspect Docker Volume
docker volume inspect my_volume
Retrieves detailed information about the Docker volume 'my_volume'.
Docker Compose Commands
Docker Compose Up
docker-compose up
Starts services defined in a docker-compose.yml
file.
Docker Compose Down
docker-compose down
Stops and removes containers, networks, and volumes defined in a docker-compose.yml
file.
Top comments (0)