Skip to main content

Dockers.. Basic commandlets


In this article we will go through some of the basic commands used in dockers.

So lets get started.


1) docker ps

This command is used to list all the running containers
ie:
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                        NAMES
4ba5baace270        couchbase           "/entrypoint.sh couc…"   8 seconds ago       Up 5 seconds        8091-8096/tcp, 11207/tcp, 11210-11211/tcp, 18091-18096/tcp   naughty_hopper
6c1773f25479        nginx               "nginx -g 'daemon of…"   5 minutes ago       Up 5 minutes        80/tcp                                                       compassionate_dijkstra


2) docker ps -a

This command list all the container into the docker, whether its in running, stopped or exited.

$ docker ps -a
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS                      PORTS                                                        NAMES
5b0868097f28        ubuntu              "/bin/bash"              7 seconds ago        Exited (0) 5 seconds ago                                                                 kind_banach
158f85fad233        ubuntu              "/bin/bash"              51 seconds ago       Exited (0) 46 seconds ago                                                                amazing_hertz
4ba5baace270        couchbase           "/entrypoint.sh couc…"   About a minute ago   Up About a minute           8091-8096/tcp, 11207/tcp, 11210-11211/tcp, 18091-18096/tcp   naughty_hopper
6c1773f25479        nginx               "nginx -g 'daemon of…"   7 minutes ago        Up 7 minutes                80/tcp                                                       compassionate_dijkstra


3) docker images ( Deleting image)

This command list all the images available into the docker host or system.

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              ed21b7a8aee9        4 days ago          127MB
couchbase           latest              fe5da7e004db        6 weeks ago         1.17GB
redis               latest              857c4ab5f029        8 months ago        98.2MB
weaveworks/scope    1.11.4              a082d48f0b39        8 months ago        78.5MB
ubuntu              latest              3556258649b2        8 months ago        64.2MB
alpine              latest              b7b28af77ffe        8 months ago        5.58MB


4) docker stop... ( Deleting a container)

This command is used to stop the running container from the docker host or system.

#First list the images into the local repository.
$ docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                                                        NAMES
f8cc904381dc        ubuntu              "sleep 100"              51 seconds ago      Up 50 seconds                                                                    gracious_dhawan
4ba5baace270        couchbase           "/entrypoint.sh couc…"   11 minutes ago      Up 11 minutes       8091-8096/tcp, 11207/tcp, 11210-11211/tcp, 18091-18096/tcp   naughty_hopper

                                                   
Stopping the container with ID f8cc904381dc

$ docker stop f8cc904381dc
f8cc904381dc

5) docker rm ( Deleting the container)

This command is specifically used to delete the container or containers.

$ docker rm f8cc904381dc
f8cc904381dc


6) Docker rmi ( Deleting images)

Lets see how many images we have at present.

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
nginx               latest              ed21b7a8aee9        4 days ago          127MB
couchbase           latest              fe5da7e004db        6 weeks ago         1.17GB
redis               latest              857c4ab5f029        8 months ago        98.2MB
weaveworks/scope    1.11.4              a082d48f0b39        8 months ago        78.5MB
ubuntu              latest              3556258649b2        8 months ago        64.2MB
alpine              latest              b7b28af77ffe        8 months ago        5.58MB

Now lets delete redis image

$ docker rmi redis
Untagged: redis:latest
Untagged: redis@sha256:854715f5cd1b64d2f62ec219a7b7baceae149453e4d29a8f72cecbb5ac51c4ad
Deleted: sha256:857c4ab5f0291ecbb4de238be9d5f9676e63dcc9608f70c8acc3748fe9689911
Deleted: sha256:cf8131ebc8cf48e212a6cba652c19328eb997fa360e59dfc1d5ae4e9841e52d6
Deleted: sha256:ad2aeea9a0026ba9194c4143de8846e93cea2a8851ac1c30b669c0c1040c4798
Deleted: sha256:e7a18a4c63c68b5c3848d87b970aea938032e78a14093b794e3bc8cfac4b3ab7
Deleted: sha256:2de5fabe69e135fd6c8e3ac5d5537d8943b9e964ec3b542eabc3b97ae810a4a2
Deleted: sha256:64c3e67d2d7fdeb252803ce9ed76375c756327bf88cc072b22c0fd1e24a9af2e
Deleted: sha256:d8a33133e477d367977987129313d9072e0ec80894ed4c52c2d88186f354c29a

Here the "redis" repository is completely deleted from Docker host.

7) Docker pull

Lets says, if you want to keep some of the images into docker repositories but don't want to install at present. In that case
docker pull comand is quite usefull.

$ docker pull ubuntu
Using default tag: latest
latest: Pulling from library/ubuntu
5bed26d33875: Pull complete
f11b29a9c730: Pull complete
930bda195c84: Pull complete
78bf9a5ad49e: Pull complete
Digest: sha256:bec5a2727be7fff3d308193cfde3491f8fba1a2ba392b7546b43a051853a341d
Status: Downloaded newer image for ubuntu:latest

8) Docker run

This command is used to run a containter using images.

In below example, docker create a container called "redis". Here in this case, the there was no redis images into the repository, this
will download the images if not present in repository and run the container.

$ docker run redis
Unable to find image 'redis:latest' locally
latest: Pulling from library/redis
c499e6d256d6: Already exists
bf1bc8a5a7e4: Pull complete
7564fb795604: Pull complete
ec6e86f783e4: Pull complete
1371d6223f46: Pull complete
021fd554320f: Pull complete
Digest: sha256:a732b1359e338a539c25346a50bf0a501120c41dc248d868e546b33e32bf4fe4
Status: Downloaded newer image for redis:latest

9) Exec - execute a command

The "exec" command print the specific result as per given command.

In below command, exec command print the output of "cat /etc/hosts/
$ docker exec 6c1773f25479 cat /etc/hosts
127.0.0.1       localhost
::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.18.0.2      6c1773f25479

10) Docker run - attach and detach

Lets run a container called "redis"

$ docker run redis
1:C 04 Apr 2020 18:57:56.714 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 04 Apr 2020 18:57:56.715 # Redis version=5.0.5, bits=64, commit=00000000, modified=0, pid=1, just started
1:M 04 Apr 2020 18:57:56.720 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command 'echo never > /sys/kernel/mm/transparent_hugepage/enabled' as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
1:M 04 Apr 2020 18:57:56.720 * Ready to accept connections
|

Here, in this command "docker run httpd" the container run infinite as we are unable to execute any other command because there was no $ prompt avaialble to execute new command.

Now, lets run the same command with detach mode (-d)
$ docker run -d redis
6c2762e502925a8ae9d371749057c41d80c1a91a85b51393e9d173e9d929197f
$

Using detached mode (-d) the container run at the background and free to execute any new command further.


11) Run - tag


Using default "docker run redis" command will install the latest redis version of container. It will pull whatever the latest version is available in docker hub repository.

$ docker run redis
Unable to find image 'redis:latest' locally
latest: Pulling from library/redis
c499e6d256d6: Pull complete
021fd554320f: Pull complete
Digest: sha256:a732b1359e338a539c25346a50bf0a501120c41dc248d868e546b33e32bf4fe4
Status: Downloaded newer image for redis:latest
1:C 04 Apr 2020 19:07:55.080 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:M 04 Apr 2020 19:07:55.082 * Ready to accept connections

We can also run container with specific version of application using TAGS. TAGS can be found from dockerhub repository

https://hub.docker.com/_/redis




Using below command, we add the tag  docker run redis:rc-buster, wehere rc-buster is the tag of version 6.0-rc3

$ docker run redis:rc-buster
Unable to find image 'redis:rc-buster' locally
rc-buster: Pulling from library/redis
7564fb795604: Already exists
3cd873a7c410: Pull complete
fd94dfb55d0e: Pull complete
Digest: sha256:cd55cd7447488fc644884bfece112c619f7940ac39b03df826c36d0ec84772fc
Status: Downloaded newer image for redis:rc-buster
1:C 04 Apr 2020 19:15:42.567 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
1:C 04 Apr 2020 19:15:42.568 # Redis version=5.9.103, bits=64, commit=00000000, modified=0, pid=1, just started
1:M 04 Apr 2020 19:15:42.569 * Running mode=standalone, port=6379.












Comments

Popular posts from this blog

Changing the FQDN of the vCenter appliance (VCSA)

This article states how to change the system name or the FQDN of the vCenter appliance 6.x You may not find any way to change the FQDN from the vCenter GUI either from VAMI page of from webclient as the option to change the hostname always be greyed out. Now the option left is from the command line of VCSA appliance. Below steps will make it possible to change the FQDN of the VCSA from the command line. Access the VCSA from console or from Putty session. Login with root permission Use above command in the command prompt of VCSA : /opt/vmware/share/vami/vami_config_net Opt for option 3 (Hostname) Change the hostname to new name Reboot the VCSA appliance.   After reboot you will be successfully manage to change the FQDN of the VCSA . Note: Above step is unsupported by VMware and may impact your SSL certificate and face problem while logging to vSphere Web Client. If you are using self-signed certificate, you can regenerate the certificate with the

Issue : Configure Management Network option is Grayed out into ESXi

Last week I got into an issue of one of my client into Vsphere environment where one of its ESXi went done out of the network. Issue was IP address was showing 0.0.0.0 on main Esxi screen and when I tried to change the network configuration, its " Configure Management network option was greyed out.  I tried to gid into it and try to analyis its vmKernal and vmwarning logs. What I found is its VMkernal switch got removed due to unexpected reason. So to resolve the issue I tried to reconfigure its vswitch0 (vmk0) by going into Tech Mode of that Exi. Below are the steps which I followed to resolve the issue. 1) Login to ESXi 2) Press F2, Check if you " Configure Management network " is greyed out or not" if yes,    follow below 3) Press ALT+F1 to move the ESXi screen to tech mode   ( This is command line like dos) 4) login with root account 5) Run the following command into it esxcli network ip interface add --interface-name= vmk0

Collecting Logs from NSX-T Edge nodes using CLI

  This article explains how to extract the logs from NSX-T Edge nodes from CLI. Let's view the steps involved: 1) Login to NSX-T  Edge node using CLI from admin credentials. 2) Use of  " get support-bundle " for Log extraction. get support-bundle command will extract the complete logs from NSX-T manager/Edge nodes. nsx-manager-1> get support-bundle file support-bundle.tgz 3) Last step is to us e of " copy file support-bundle.tgz url " command. copy file will forward your collected logs from the NSX-T manager to the destination(URL) host from where you can download the logs. copy file support.bundle.tgz url scp://root@192.168.11.15/tmp Here, the URL specified is the ESXi host ( 192.168.11.15) under /tmp partition where logs will be copied and from there one can extract it for further log review. Happy Learning.  :)