Table of contents
- Introduction
- List the docker version details
- — Containers —
- Start a new Container from an Image
- Assign a name to container
- Map a port to container
- Map all ports to container
- Start container in background
- Assign a hostname to container
- Show a list of running container
- Show a list of all containers
- Delete a container
- Delete a running container
- Delete stopped container
- Stop a running container
- Start a stopped container
- Copy file from container to host
- Copy file from the host to container
- Renaming a Container
- Restarting a container
- Pausing a container
- Start a shell inside a running container
- — Images —
- Download an Image
- See list of all images
- Run the docker image
- Upload an image to a repository
- Login to a Registry
- Delete an image
- Delete all unused images
- Build an image from Dockerfile
- Show the logs of container
- Show the stats of running container
- Show processes of container
- Show detailed information
- — Network —
- List all networks
- Inspect a network
- Connect a container to a network
- Disconnect a container from a network
- List networks
Introduction
The Docker tool was introduced to make it easier for developers to create, deploy, and run applications using containers. Containers provision the developers with the packaging of their applications, together with all important components they require such as libraries and other dependencies, and shipping of them all out as a single package. This assures the developers that their applications can be run on any other machine.
List the docker version details
docker version
— Containers —
Start a new Container from an Image
docker run image
docker run nginx
Assign a name to container
docker run --name CONTAINER_NAME IMAGE
docker run --name web nginx
Map a port to container
docker run -p 80:80 nginx
Map all ports to container
docker run -P IMAGE
docker run -P nginx
Start container in background
docker run -d IMAGE
docker run -d nginx
Assign a hostname to container
docker run --hostname HOSTNAME IMAGE
docker run --hostname myhost nginx
Show a list of running container
docker ps
Show a list of all containers
docker ps -a
Delete a container
docker rm CONTAINER_NAME
docker rm web
Delete a running container
docker rm -f CONTAINER_NAME
docker rm -f web
Delete stopped container
docker container prune
Stop a running container
docker stop CONTAINER_NAME
docker stop web
Start a stopped container
docker start CONTAINER_NAME
docker start web
Copy file from container to host
docker cp CONTAINER_NAME:SOURCE TARGET
docker cp web:/index.html index.html
Copy file from the host to container
docker cp TARGET CONTAINER_NAME:HOST
docker cp index.html web:/index.html
Renaming a Container
docker stop old_name new_name
docker rename myweb web
Restarting a container
docker stop CONTAINER_NAME
docker restart web
Pausing a container
docker pause CONTAINER_NAME
docker pause web
Start a shell inside a running container
docker exec -it CONTAINER_NAME SHELL_NAME
docker exec -it web bash
— Images —
Download an Image
docker pull IMAGE[:TAG]
docker pull nginx:1.0
See list of all images
docker images
Run the docker image
docker run IMAGE_NAME
docker run nginx
Upload an image to a repository
docker push IMAGE_NAME:TAG
docker push my_image:1.0
Login to a Registry
docker logindocker login localhost:8080
Delete an image
docker rmi IMAGE_NAME
docker rmi nginx
Delete all unused images
docker image prune -a
Build an image from Dockerfile
docker build . -t IMAGE_NAME
Show the logs of container
docker logs CONTAINER_NAME
docker logs my_web
Show the stats of running container
docker stats [container_Id]
Show processes of container
docker top CONTAINER_NAME
docker top my_web
Show detailed information
docker inspect CONTAINER_NAME
docker inspect my_web
— Network —
List all networks
docker network ls
Inspect a network
docker network inspect NETWORK_NAME
docker network inspect br0
Connect a container to a network
docker network connect NETWORK_NAME CONTAINER_NAME
docker network connect br0 my_web
Disconnect a container from a network
docker network disconnect NETWORK_NAME CONTAINER_NAME
docker network disconnect br0 my_web
List networks
docker tag IMAGE_NAME NEW_IMAGE_NAME
docker tag nginx:1.0 nginx:1.1
THAT'S ALL FOR TODAY'S LEARNING I HOPE YOU LEARN SOMETHING FROM THIS BLOG