Sunday, June 18, 2023

Docker Basic Commands

Docker Basic Commands 


# To start and enable docker 
$ sudo systemctl start docker 
$ sudo systemctl enable docker

# To check docker status 
$ sudo systemctl status docker

# To check docker Version 
$ docker --version

# To see docker info 
$ docker info

# To see docker images
$ docker images

# Pulling hello-world docker image 
$ docker pull hello-world

# To see docker image 
$ docker images

# Running hello-world docker image 
$ docker run hello-world

# Display Running Docker containers
$ docker ps

# Displaying Running + stopped containers
$ docker ps -a

# Inspect docker image
$ docker inspect <image-id>

# Remove Docker image
$ docker rmi <image-name / image-id>

# Remove docker image forcefully
$ docker rmi -f <image-name / image-id>

# Remove docker container
$ docker rm <container-id/container-name>

# To remove all images from the server:
$ docker rmi -f $(docker images -q)

# Remove all stopped containers + un-used images + un-used networks 
$ docker system prune -a

# To see docker images location:

[root@localhost sha256]# pwd
/var/lib/docker/image/overlay2/imagedb/content/sha256

To remove all stopped containers:
$ docker container prune

To start a container using image

[root@localhost sha256]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
docker.io/httpd     latest              d1676199e605        13 days ago         145 MB

Using 1 image we can create multiple containers.

docker run -it --name abcd httpd:latest
docker run -it --name abcde httpd:latest
docker run -it -d --name abcdef httpd:latest
docker run -it -d --name abcdefg httpd:latest

-d ------> detacched mode
-i ------> interactive mode
-t ------> tty terminal

No comments:

Post a Comment