Warning!

Don't start this step until you have completed the previous step. Make sure you are in root@pod01-srv01 during these steps.

Docker Commands

During the previous section "Contiv installation" multiple components were installed for you automatically, such as:

In this section we will be running some basic commands to become more familiar with this lab. It is important to note that you can always visit http://docs.docker.com to get more information about these commands and other Docker commands.

Step 1 - Export environments

We need to export the DOCKER_HOST environment variables to know where the Docker Remote API is located.

pod01-srv1
1
# This is the copy group: 1
export DOCKER_HOST=tcp://pod01-srv1.ecatsrtpdmz.cisco.com:2375
pod01-srv1
2
# This is the copy group: 2
cd ~ sed -i -e '$a export DOCKER_HOST=tcp://pod01-srv1.ecatsrtpdmz.cisco.com:2375' .bashrc
pod01-srv1
3
# This is the copy group: 3
cat .bashrc
[root@pod-srv1 ~]# cat .bashrc
# .bashrc

# User specific aliases and functions

alias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'

# Source global definitions
if [ -f /etc/bashrc ]; then
        . /etc/bashrc
fi
export DOCKER_HOST=tcp://pod01-srv1.ecatsrtpdmz.cisco.com:2375
    

Step 2 - Docker Version

This command will display the Docker Version your Docker Engine is currently running.

pod01-srv1
4
# This is the copy group: 4
docker --version
pod01-srv1

[root@pod01-srv1 ~]#docker --version
Docker version 17.12.0-ce, build c97c6d6

Step 3 - Docker Network

During the installation process Docker will be installing three networks.

pod01-srv1
5
# This is the copy group: 5
docker network ls
pod01-srv1

[root@pod01-srv1 ~]#docker network ls
NETWORK ID          NAME                                      DRIVER
8713b6b1a7f6        pod01-srv1.ecatsrtpdmz.cisco.com/bridge   bridge
82497573b10b        pod01-srv1.ecatsrtpdmz.cisco.com/host     host
ae67fd1290a0        pod01-srv1.ecatsrtpdmz.cisco.com/none     null
5d930ac93f1f        pod01-srv2.ecatsrtpdmz.cisco.com/bridge   bridge
89dca9c64e0a        pod01-srv2.ecatsrtpdmz.cisco.com/host     host
37cc782ca877        pod01-srv2.ecatsrtpdmz.cisco.com/none     null


Note: You will notice that both of your servers are showing in this output this is because we are running a cluster. We will be explaining this further down.

Step 4 - Docker Network Inspect

This command will provide container information, IP address/Gateway and in our case information pertaining swarm configuration.

pod01-srv1
6
# This is the copy group: 6
docker network inspect pod01-srv1.ecatsrtpdmz.cisco.com/bridge
pod01-srv1

[root@pod01-srv1 ~]#docker network inspect pod01-srv1.ecatsrtpdmz.cisco.com/bridge
[
    {
        "Name": "bridge",
        "Id": "afb6a74e3fcf0fb2694d1ab5b764b4ce90fd2c5e12c15e723849c7371289e59f",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.17.0.0/16"
                }
            ]
        },
        "Internal": false,
        "Containers": {},
        "Options": {
            "com.docker.network.bridge.default_bridge": "true",
            "com.docker.network.bridge.enable_icc": "true",
            "com.docker.network.bridge.enable_ip_masquerade": "true",
            "com.docker.network.bridge.host_binding_ipv4": "0.0.0.0",
            "com.docker.network.bridge.name": "docker0",
            "com.docker.network.driver.mtu": "1500"
        },
        "Labels": {}
    }
]

Step 5 - Docker Pull

This command allows you to download images from either hub.docker.com or your own repository. We will use this command to download the images we will be leveraging during this lab.

The first image we are going to be downloading is a webserver.

pod01-srv1
7
# This is the copy group: 7
docker pull cobedien/ltrcld-2003
pod01-srv1

[root@pod01-srv1 ~]#docker pull cobedien/ltrcld-2003
Using default tag: latest
Using default tag: latest
pod01-srv1.ecatsrtpdmz.cisco.com: Pulling cobedien/ltrcld-2003... : downloaded
pod01-srv2.ecatsrtpdmz.cisco.com: Pulling cobedien/ltrcld-2003... : downloaded


NOTE: We are pulling the images to both of our nodes.


Step 6 - Docker Images

Docker images allows to query all the images that are currently in the system. Note that cobedien/webserver is there.

pod01-srv1
8
# This is the copy group: 8
docker images
pod01-srv1

[root@pod01-srv1 ~]#docker images
REPOSITORY            TAG                 IMAGE ID            CREATED             SIZE
cobedien/ltrcld-2003   latest              f0e3ee818195        3 days ago          224.7 MB
contiv/aci-gw          02-02-2017.2.1_1h   2db0d82d9452        3 days ago          809.1 MB
contiv/auth_proxy      1.0.0-alpha         0e3e991c962a        5 days ago          28.4 MB
swarm                  1.2.5               f1d5a057a389        5 months ago        19.47 MB
quay.io/coreos/etcd    v2.3.7              e81032a59e55        7 months ago        32.29 MB


Step 7 - Docker Run

Docker run starts the container. It also provides the isolation of the container in which the process runs on the host. It is important to note that each container process runs its own isolated file system, network stack, and process tree. This command has several flags. You can execute docker run --help in order to learn about them.

pod01-srv1
9
# This is the copy group: 9
docker run -it -h=webserver --name=webserver cobedien/ltrcld-2003
pod01-srv1

[root@pod01-srv1 ~]#docker run -it -h=webserver --name=webserver cobedien/ltrcld-2003
root@webserver:/#

NOTE: Now you are inside your first container!!! Congratulations!!! Feel free to navigate and execute commands.


BONUS CHALLENGE: Can you find out what OS is this container running? If you find the answer please contact the instructor.

To exit the container you can do it via two ways:

Enter control+p+q in order to keep the container running.

Step 8 - Docker ps

Docker ps will show the active/running containers (by default):

pod01-srv1
10
# This is the copy group: 10
docker ps
pod01-srv1

[root@pod01-srv1 ~]#docker ps
CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS              PORTS               NAMES
689c6ca1b6b8        cobedien/ltrcld-2003              "/bin/bash"              48 seconds ago      Up 40 seconds       80/tcp              pod01-srv2.ecatsrtpdmz.cisco.com/webserver
406f65539fb7        contiv/auth_proxy:1.0.0-alpha     "./auth_proxy --tls-k"   14 minutes ago      Up 14 minutes                           pod01-srv1.ecatsrtpdmz.cisco.com/auth-proxy
9361de3143ab        contiv/aci-gw:02-02-2017.2.1_1h   "/bin/sh -c '/usr/bin"   16 minutes ago      Up 16 minutes                           pod01-srv1.ecatsrtpdmz.cisco.com/contiv-aci-gw
ea6fb755040d        quay.io/coreos/etcd:v2.3.7        "/etcd"                  28 minutes ago      Up 28 minutes                           pod01-srv2.ecatsrtpdmz.cisco.com/etcd
43e03ce05403        quay.io/coreos/etcd:v2.3.7        "/etcd"                  29 minutes ago      Up 29 minutes                           pod01-srv1.ecatsrtpdmz.cisco.com/etcd


    

As you can see the webserver container still running because in the previous step we used control+p+q.

Step 9 - Docker stop

Docker stop allows to stop a running container.

pod01-srv1
11
# This is the copy group: 11
docker stop webserver
pod01-srv1

[root@pod01-srv1 ~]#docker stop webserver
webserver

Now let's verify the container is not longer running

pod01-srv1
12
# This is the copy group: 12
docker ps
pod01-srv1

[root@pod01-srv1 ~]#docker ps
CONTAINER ID        IMAGE                        COMMAND                  CREATED             STATUS              PORTS               NAMES
e3671557032a        contiv/auth_proxy:1.0.0-alpha     "./auth_proxy --tls-k"   26 minutes ago      Up 26 minutes                           pod01-srv1.ecatsrtpdmz.cisco.com/auth-proxy
6227ce912b36        contiv/aci-gw:12-01-2016.2.1_1h   "/bin/sh -c '/usr/bin"   27 minutes ago      Up 27 minutes                           pod01-srv1.ecatsrtpdmz.cisco.com/contiv-aci-gw
3f89851a8639        quay.io/coreos/etcd:v2.3.7        "/etcd"                  35 minutes ago      Up 35 minutes                           pod01-srv2.ecatsrtpdmz.cisco.com/etcd
1b70f7a77fe7        quay.io/coreos/etcd:v2.3.7        "/etcd"                  35 minutes ago      Up 35 minutes                           pod01-srv1.ecatsrtpdmz.cisco.com/etcd

As you can see the webserver container is not longer running. You can execute docker ps --all to show every container running/not running.

You can start the container again by doing docker start webserver

Step 10 - Docker rm

docker rm deletes the container from the host

pod01-srv1
13
# This is the copy group: 13
docker rm webserver
pod01-srv1

[root@pod01-srv1 ~]#docker rm webserver
webserver

Step 11 - Docker Swarm Commands

Docker info

Docker info is probably the most useful command to use in a swarm environment. This command will provide several pieces of information such as version, number of nodes, information about the nodes, status, etc

pod01-srv1
14
# This is the copy group: 14
docker info
pod01-srv1

[root@pod01-srv1 ~]#docker info
Containers: 8
 Running: 8
 Paused: 0
 Stopped: 0
Images: 10
Server Version: swarm/1.2.5
Role: primary
Strategy: spread
Filters: health, port, containerslots, dependency, affinity, constraint
Nodes: 2
 pod01-srv1.ecatsrtpdmz.cisco.com: 10.0.236.17:2385
  â”” ID: VL2K:KYDV:LJVR:UEIK:TY6V:G4FL:RALX:77IS:ZZIJ:OIUD:3ZJB:VNJ6
  â”” Status: Healthy
  â”” Containers: 4 (4 Running, 0 Paused, 0 Stopped)
  â”” Reserved CPUs: 0 / 1
  â”” Reserved Memory: 0 B / 3.888 GiB
  â”” Labels: kernelversion=3.10.0-514.2.2.el7.x86_64, operatingsystem=CentOS Linux 7 (Core), storagedriver=devicemapper
  â”” UpdatedAt: 2017-01-12T15:58:47Z
  â”” ServerVersion: 1.11.1
 pod01-srv2.ecatsrtpdmz.cisco.com: 10.0.236.49:2385
  â”” ID: 7S3J:W5JA:N3XK:PEUN:IKFJ:ELLK:2RDW:6HON:L2HB:CPEF:5ABC:M6JE
  â”” Status: Healthy
  â”” Containers: 4 (4 Running, 0 Paused, 0 Stopped)
  â”” Reserved CPUs: 0 / 1
  â”” Reserved Memory: 0 B / 3.888 GiB
  â”” Labels: kernelversion=3.10.0-514.2.2.el7.x86_64, operatingsystem=CentOS Linux 7 (Core), storagedriver=devicemapper
  â”” UpdatedAt: 2017-01-12T15:58:46Z
  â”” ServerVersion: 1.11.1
Plugins:
 Volume:
 Network:
Kernel Version: 3.10.0-514.2.2.el7.x86_64
Operating System: linux
Architecture: amd64
CPUs: 2
Total Memory: 7.775 GiB
Name: c6888c3f2b61
Docker Root Dir:
Debug mode (client): false
Debug mode (server): false
WARNING: No kernel memory limit support

As you can see from the above output both of our servers are part of the cluster and the status is healthy. It is also showing the number of containers each worker node has.

Now that you are familiar with Swarm, let's check how containers are distributed across the cluster. Let's start another container and check in which Docker Engine (host) got placed. The output may be there. Let's create four containers and see where each container gets placed by Docker Swarm.

pod01-srv1
15
# This is the copy group: 15
docker run -itd --name=webserver cobedien/ltrcld-2003 sleep 6000 docker run -itd --name=webserver1 cobedien/ltrcld-2003 sleep 6000 docker run -itd --name=webserver2 cobedien/ltrcld-2003 sleep 6000 docker run -itd --name=webserver3 cobedien/ltrcld-2003 sleep 6000
pod01-srv1
16
# This is the copy group: 16
docker ps | grep webserver
pod01-srv1

[root@pod01-srv1 ~]#  docker ps | grep webserver
CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS              PORTS               NAMES
d26fa93c0edb        cobedien/ltrcld-2003         "/bin/bash"              5 seconds ago       Up 1 seconds        80/tcp              pod01-srv1.ecatsrtpdmz.cisco.com/webserver3
979a00046921        cobedien/ltrcld-2003         "/bin/bash"              8 seconds ago       Up 5 seconds        80/tcp              pod01-srv2.ecatsrtpdmz.cisco.com/webserver2
b88f623976fd        cobedien/ltrcld-2003         "/bin/bash"              11 seconds ago      Up 8 seconds        80/tcp              pod01-srv2.ecatsrtpdmz.cisco.com/webserver1
5f1464eb0d3c        cobedien/ltrcld-2003         "/bin/bash"              13 seconds ago      Up 11 seconds       80/tcp              pod01-srv2.ecatsrtpdmz.cisco.com/webserver

You will notice that some containers were placed in pod01-srv1.ecatsrtpdmz.cisco.com and the rest of the containers were placed in pod01-srv2.ecatsrtpdmz.cisco.com

Docker Swarm is keep tracking of the placement and balancing the placement of the container based in a load balacing algorithm

Let's remove the containers we just created in order to keep our system clean and continue with the lab.

pod01-srv1
17
# This is the copy group: 17
docker rm -f webserver docker rm -f webserver1 docker rm -f webserver2 docker rm -f webserver3
© Copyright Cisco Systems 2017