Useful docker commands for day to day use
How to download image from docker hub
docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
Digest: sha256:e1c082e3d3c45cccac829840a25941e679c25d412c2fa221cf1a824e6a
Status: Image is up to date for alpine:latest
docker.io/library/alpine:latest
docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest bb3de5531c18 3 weeks ago 5.34MB
pankajdwivedi@Pankajs-MacBook-Air ~ %
docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
alpine latest bb3de5531c18 3 weeks ago 5.34MB
docker container run --name alp -it alpine
/ #
docker run --name alp -it alpine
/ #
- run : giving command to run the container
- --name alp : giving name to your container (It's always a better idea to give your container name)
- -it : running container in interactive mode
- alpine : is image name which you just pulled.
- -d : detach mode
docker run --name alp -dit alpine
a6ba34f88715cf3d63879872a65d6a7aeb48572ee7a79fb22ecf751049c49dc2
To enter in a container's shell you need below command:
docker exec -it alp /bin/sh
/ #
Since we have started our alp container, let's check if it is running. Using docker ps
docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a6ba34f88715 alpine "/bin/sh" 4 minutes ago Up 4 minutes alp
How to check logs
docker logs alp
/ # exit
How to start and stop container
docker stop alp
alp
docker start alp
alp
How to inspect container
docker inspect alp
[
{
"Id": "a6ba34f88715cf3d638797a79fb22ecf751049c49dc2",
"Created": "2021-09-19T08:04:17.202282Z",
"Path": "/bin/sh",
"Args": [],
"State": {
"Status": "running",
"Running": true,
docker inspect alp | egrep "IPAddress"
"SecondaryIPAddresses": null,
"IPAddress": "172.17.0.2",
"IPAddress": "172.17.0.2",
docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 1 1 5.337MB 0B (0%)
Containers 3 1 15B 10B (66%)
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
How to check diff of container
docker diff alp
C /root
A /root/.ash_history
How to remove all containers running.
docker stop $(docker ps -q)
a6ba34f88715
docker rm alp
alp
Remove all stopped containers
docker container prune
WARNING! This will remove all stopped containers.
Are you sure you want to continue? [y/N] y
Deleted Containers:
803ec8603418b8e5ca7cbe9178724ca2714ab3fba48ac406282e78
7a8ee73bef1b766d38594ceeed8bdabf0cbc4e114faa65de71492a
Total reclaimed space: 10B
Remove all images
docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
Delete alpine image
docker image rm alpine
Untagged: alpine:latest
Untagged: alpine@sha256:e1c082e3d3c45cccahe679c25d438cc8412c2fa221cf1a824e6a
Deleted: sha256:bb3de5531c18f185667b0be0e400ab244440093de82baf4072e14af3b84
Deleted: sha256:ee420dfed78aeb92dbd73a3fbb59fa5dac4e04639210cc7905
docker system df
TYPE TOTAL ACTIVE SIZE RECLAIMABLE
Images 0 0 0B 0B
Containers 0 0 0B 0B
Local Volumes 0 0 0B 0B
Build Cache 0 0 0B 0B
No comments:
Post a Comment