Reading Time: 4 minutes































































Basic Commands:
- Check Version of Docker
Command:
docker --version OR docker -v

- download image
Command:
docker pull image_name
Example:
docker pull nginx

- Listing images
Command:
docker images



- Listing Containers
Command:
docker container ls OR docker ps


Run a new Container
- Start a new container from image
Command:
docker run image
Example:
docker run nginx


- Assign it a name
Command:
docker run --name CONTAINER IMAGE
Example:
docker run --name agitated_swartz nginx


- Mapping a port to container image
Command:
docker run -p HOSTPORT:CONTAINERPORT IMAGE
Example:
docker run -p 8080:80 nginx


- Start container in the background
Command:
docker run -d IMAGE
Example:
docker run -d nginx


Manage Containers
- Show a list of running containers
docker ps


- Show a list of all containers
docker ps -a


- Delete a container
Command:
docker rm CONTAINER
Example:
docker rm web


- Delete stopped containers
docker container prune


- Create an image out of container
Command:
docker commit container
Example:
docker commit agitated_swartz1


- Rename a container
Command:
docker rename old_name new_name
Example:
docker rename agitated_swartz web


- Start a shell inside a running container
Command:
docker exec -it container executable
Example:
docker exec -it web bash


Manage Images
- Download an image
Command:
docker pull image[:tag]
Example:
docker pull nginx



- Upload an image to a repository
Command:
docker push image
Example:
docker push myimage:1.0


- Delete an image
Command:
docker rmi image
Example:
docker rmi nginx


- Show a list of all images
docker images



- Delete all unused images
Command:
docker image prune -a


- Delete dangling images
Command:
docker image prune


- Build an image from a docker file
Command:
docker build DIRECTORY OR docker build


- Tag an image
Command:
docker tag image NEW_IMAGE
Example:
docker tag Ubuntu Ubuntu:20.04


Save an image to Tar File
Command:
docker save image > File
Example:
docker save nginx > nginx.tar


- Load an image from a tar file
Command:
docker load -i TARFILE
Example:
docker load -i nginx.tar


Info & Stats
- Show the logs of a container
Command:
docker logs container
Example:
docker logs web


- Show stats of a running container
Command:
docker stats


- Show processes of container
Command:
docker top CONTAINER
Example:
docker top web


- Get detailed info about an object
Command:
docker INSPECT name
Example:
docker inspect nginx


- Show all modified files in Container
Command:
docker diff container
Example:
docker diff web


- Show mapped ports of a container
Command:
docker port CONTAINER
Example:
docker port web

