Part1 - Docker Commands with Examples

1 Likes
over 1 year ago

I will use "Risk service" for the reference in the examples. If you are not aware, Risk Service is bundled inside the Advanced Authentication appliance.

1. docker --version

Use this command to get the currently installed version of the docker.

Example:  lakhil@lakhil-docker:~$ docker --version

Docker version 19.03.3, build a872fc2f86

2. docker pull <image name>

Use this command to pull images from the docker registry to the local store.

Example: docker pull hello-world

Refer to this URL for more information.

3. docker images

Use this command to list all the locally stored docker images.

docker-image-help.PNG

4. docker ps

Use this command to list the running containers

docker-ps-help.PNG

5. docker ps -a

Use this command to show all the running and exited containers

6. docker exec -it <container id> bash

Use this command to access the running container

Example:  To go inside the shell of the container

lakhil@lakhil-docker:~$ docker exec -it 4f38323ca234 /bin/sh

In the above command "4f38323ca234" is the container ID. You need to run the "docker ps" command to see the container ID.

You can also get an output of the shell commands without going inside the container.

Example (a): lakhil@lakhil-docker:~$ docker exec -it 4f38323ca234 ls -l
total 8
drwxr-xr-x 2 novlwww root 4096 Mar 11 2019 bin
-rwxr-xr-x 1 root root 458 Jun 12 08:29 startup.sh

(b) lakhil@lakhil-docker:~$ docker exec -it 4f38323ca234 ps -ef
UID PID PPID C STIME TTY TIME CMD
novlwww 1 0 0 08:32 ? 00:00:00 /bin/sh ./startup.sh
novlwww 83 1 1 08:34 ? 00:00:44 /opt/netiq/common/jre/bin/java -
novlwww 1703 1 0 09:31 ? 00:00:00 sleep 5
novlwww 1704 0 30 09:31 pts/0 00:00:00 ps -ef

7. docker volume ls

Use this command to list all the volumes known to Docker.

docker-volume-help.PNG

 

docker-volume-example.PNG

 

Use inspect to get more details about a volume.

docker-volume-inspect.PNG

 

8. docker stats

Use this command to live stream container's runtime metrics.

docker-stats-help.PNG

docker-stats-example.PNG

To limit data to one or more specific containers, specify a list of container names or ids separated by a space.

docker-stats-container.PNG

 

 

9. docker system df

Use this command to understand the docker’s disk usage.

docker-system-help.PNG

 docker-system-df.PNG

10. docker stop <container id>
Use this command to stop a running container.

Labels:

Other
Education-Training
Comment List
Anonymous
Related Discussions
Recommended