Step Docker Installation in Linux

in #utopian-io7 years ago (edited)

docker.png


The default swarm docker is already included in version 1.12, the good news is that it is very easy to configure. You do not have to bother to configure as in the version before version 1.12.

This time I will demonstrate how easy it is to setup the swarm docker in version 1.12, at the time of this writing I am using Ubuntu Xenial (16.04 LTS) and using the repository from the docker. in this lab I use five servers with two as manager and three as worker. In naming the node, I use the name of manager-X and worker-Y to show the function of the node itself.

For IP settings, the manager will be running IP 192.168.0.11 up to 192.168.0.99, and the worker will have ip ranging from 192.168.0.101 to 192.168.0.254.

Ensuring docker version
Please make sure that your docker has version 1.12 or higher.
$ docker version
Docker version 1.12.1, build 23cf638

From the above results show that my docker is version 1.12.1 so installation will be easy.

or if you have not installed the docker either in the manager or in the worker, you can use the docker-machine to install the docker-engine. Previously make sure that you can login with a key so that you can login with passwordless

To setup sshkey please type:

$ ssh-keygen -t ecdsa
Generating public/private ecdsa key pair.
Enter file in which to save the key (/home/ubuntu/.ssh/id_ecdsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/ubuntu/.ssh/id_ecdsa.
Your public key has been saved in /home/ubuntu/.ssh/id_ecdsa.pub.
The key fingerprint is:
20:96:c8:f6:5a:5c:cc:cd:8c:33:45:97:de:a3:55:61 ubuntu@localhost
The key's randomart image is:
+--[ECDSA 256]---+
| .o .. E. |
| . . + * .. .. |
| + + O +. . . |
| . + o + . + |
| + S o . |
| o . |
| . |
| |
| |
+-----------------+
Next please copy the ssh key to the machine manager and worker with the following command:
$ ssh-key-id 192.168.0.11
You will be asked for a password to login. please enter the password of your user
Next is to install with docker-machine:
$ docker-machine create --driver generic --generic-ip-address=$IP-ADDPRESS
--generic-ssh-key ~/.ssh/$KEY --generic-ssh-user $USER manager-1
Example if you want to install manager-1 with user ubuntu and ssh ecdsa example is as follows:
$ docker-machine create --driver generic --generic-ip-address=192.168.0.11
--generic-ssh-key ~/.ssh/id_ecdsa --generic-ssh-user ubuntu manager-1
Please repeat to manager-2 and worker 1 to worker-3, then verify with the following command:
$ docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM DOCKER ERRORS
worker-1 - generic Running tcp://192.168.0.101:2376 v1.12.1
worker-2 - generic Running tcp://192.168.0.102:2376 v1.12.1
worker-3 - generic Running tcp://192.168.0.103:2376 v1.12.1
manager-2 - generic Running tcp://192.168.0.12:2376 v1.12.1
manager-1 * generic Running tcp://192.168.0.11:2376 v1.12.1

Start the swarm docker setup

To get started, please login on the node in charge as manager, and type the following command:

$ docker swarm init --advertise-addr 192.168.0.11

The result:
Swarm initialized: current node (erk63hyz95hy7s1giwd0mjjmp) is now a manager.
To add a worker to this swarm, run the following command:

docker swarm join \
--token SWMTKN-1-6b7ymr9y759fbtfggbh3dp2wst0vrezo2sw3dv6iz79otkdsc6-d9a8l921hjyql4mub3oh1117g \
192.168.0.11:2377

To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.

only that? yes just that, the above command to make initials of docker swarm in manager.

Verify with docker info command

$ docker info
Containers: 73
Running: 0
Paused: 0
Stopped: 73
Images: 103
Server Version: 1.12.1
Storage Driver: aufs
Root Dir: /var/lib/docker/aufs
Backing Filesystem: extfs
Dirs: 592
Dirperm1 Supported: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
Volume: local
Network: null bridge overlay host
Swarm: active
NodeID: erk63hyz95hy7s1giwd0mjjmp
Is Manager: true
ClusterID: 30ty62s2py73okcei9kmr95o5
Managers: 1
Nodes: 1

$ docker node ls
ID HOSTNAME STATUS AVAILABILITY MANAGER STATUS
erk63hyz95hy7s1giwd0mjjmp * manager-1 Ready Active Leader

it appears that the swarm docker is active even if only one node is active

Configure client
Please login to manager-1 to get token manager:

$ docker swarm join-token manager
To add a manager to this swarm, run the following command:

docker swarm join \
--token SWMTKN-1-6b7ymr9y759fbtfggbh3dp2wst0vrezo2sw3dv6iz79otkdsc6-0ou18lotoo36mjq0e4s0apuo5 \
192.168.0.11:2377

Please login to manager-2 and type the above command:

$ docker swarm join
--token SWMTKN-1-6b7ymr9y759fbtfggbh3dp2wst0vrezo2sw3dv6iz79otkdsc6-0ou18lotoo36mjq0e4s0apuo5
192.168.0.11:2377

This node joined a swarm as a manager.
The next step is to log in to worker-1 to worker-3 and type in the commands obtained when initializing the swarm docker

$ docker swarm join
--token SWMTKN-1-6b7ymr9y759fbtfggbh3dp2wst0vrezo2sw3dv6iz79otkdsc6-d9a8l921hjyql4mub3oh1117g
192.168.0.11:2377

Verifikasi swarm
After testing all managers and nodes, please verify from the manager with the following command:

$ eval $(docker-machine env --swarm manager-1)
$ docker info
Containers: 6
Running: 2
Paused: 0
Stopped: 4
Images: 31
Server Version: swarm/1.2.4
Role: primary
Strategy: spread
Filters: health, port, containerslots, dependency, affinity, constraint
Nodes: 5
manager-2: 192.168.10.12:2376
└ ID: 3KQB:C4DQ:AV46:NX7O:XN6Y:EP24:3XLH:UO4D:5N2R:SDAX:AJR6:CI3T
└ Status: Healthy
└ Containers: 1 (0 Running, 0 Paused, 1 Stopped)
└ Reserved CPUs: 0 / 4
└ Reserved Memory: 0 B / 8.185 GiB
└ Labels: kernelversion=4.4.0-31-generic, operatingsystem=Ubuntu 16.04.1 LTS, provider=generic, storagedriver=aufs
└ UpdatedAt: 2016-08-18T21:26:24Z
└ ServerVersion: 1.12.1
worker-1: 192.168.10.111:2376
└ ID: VO22:NU4C:ODDV:R2TL:HVV2:2E4I:MKAW:SBRO:WWFD:T265:HPNY:JKZI
└ Status: Healthy
└ Containers: 1 (0 Running, 0 Paused, 1 Stopped)
└ Reserved CPUs: 0 / 4
└ Reserved Memory: 0 B / 8.185 GiB
└ Labels: kernelversion=4.4.0-31-generic, operatingsystem=Ubuntu 16.04.1 LTS, provider=generic, storagedriver=aufs
└ UpdatedAt: 2016-08-18T21:26:37Z
└ ServerVersion: 1.12.1
worker-2: 192.168.10.112:2376
└ ID: AFYB:C2IM:Z276:RWMN:CODJ:SHKM:IFX6:POWT:VZKO:BHVS:UBAQ:QVJC
└ Status: Healthy
└ Containers: 1 (0 Running, 0 Paused, 1 Stopped)
└ Reserved CPUs: 0 / 4
└ Reserved Memory: 0 B / 8.185 GiB
└ Labels: kernelversion=4.4.0-31-generic, operatingsystem=Ubuntu 16.04.1 LTS, provider=generic, storagedriver=aufs
└ UpdatedAt: 2016-08-18T21:26:25Z
└ ServerVersion: 1.12.1
worker-3: 192.168.10.113:2376
└ ID: PGC3:TJJR:GCRG:5RKA:Q4N3:LWHF:3TAO:FDD2:TY6F:DOUK:27WS:76MQ
└ Status: Healthy
└ Containers: 1 (0 Running, 0 Paused, 1 Stopped)
└ Reserved CPUs: 0 / 4
└ Reserved Memory: 0 B / 8.185 GiB
└ Labels: kernelversion=4.4.0-31-generic, operatingsystem=Ubuntu 16.04.1 LTS, provider=generic, storagedriver=aufs
└ UpdatedAt: 2016-08-18T20:18:37Z
└ ServerVersion: 1.12.1
manager-1: 192.168.10.11:2376
└ ID: HEN3:HWX4:2XTZ:EL5B:YUK3:JUH2:YZ2N:XD77:OTPW:ZONP:UYVP:MYDG
└ Status: Healthy
└ Containers: 2 (2 Running, 0 Paused, 0 Stopped)
└ Reserved CPUs: 0 / 8
└ Reserved Memory: 0 B / 8.087 GiB
└ Labels: kernelversion=4.4.0-21-generic, operatingsystem=Ubuntu 16.04.1 LTS, provider=generic, storagedriver=aufs
└ UpdatedAt: 2016-08-18T21:26:45Z
└ ServerVersion: 1.12.1
Plugins:
Volume:
Network:
Swarm:
NodeID:
Is Manager: false
Node Address:
Security Options:
Kernel Version: 4.4.0-21-generic
Operating System: linux
Architecture: amd64
CPUs: 24
Total Memory: 40.83 GiB
Name: 6f894401a6f4
Docker Root Dir:
Debug Mode (client): false
Debug Mode (server): false
WARNING: No kernel memory limit support
Congratulations docker-swarm has been installed!
Deploy service di swarm
After creating cluster swarm, we will try to make service in swarm. we will make
nginx di cluster. Please login in manager-1

$ docker service create --replicas 3 --name nginx nginx

Here are the results of the docker services above:

$ docker service ls
ID NAME REPLICAS IMAGE COMMAND
cp2er0hu010r nginx 3/3 nginx

$ docker service inspect nginx
[
{
"ID": "cp2er0hu010rl0qbv0714t8pw",
"Version": {
"Index": 21053
},
"CreatedAt": "2016-08-18T22:28:01.748449495Z",
"UpdatedAt": "2016-08-18T22:28:01.748449495Z",
"Spec": {
"Name": "nginx",
"TaskTemplate": {
"ContainerSpec": {
"Image": "nginx"
},
"Resources": {
"Limits": {},
"Reservations": {}
},
"RestartPolicy": {
"Condition": "any",
"MaxAttempts": 0
},
"Placement": {}
},
"Mode": {
"Replicated": {
"Replicas": 3
}
},
"UpdateConfig": {
"Parallelism": 1,
"FailureAction": "pause"
},
"EndpointSpec": {
"Mode": "vip"
}
},
"Endpoint": {
"Spec": {}
},
"UpdateStatus": {
"StartedAt": "0001-01-01T00:00:00Z",
"CompletedAt": "0001-01-01T00:00:00Z"
}
}
]

$ docker service ps nginx
ID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR
8ihthj14i9qitl792vatmrqjj nginx.1 nginx worker-1 Running Running 2 minutes ago
48eq2nah2txv7yxthk5y3158m nginx.2 nginx worker-2 Running Running 2 minutes ago
8yv7z3bk25h7jf06yf6y9hivm nginx.3 nginx manager-1 Running Running 3 minutes ago



Posted on Utopian.io - Rewarding Open Source Contributors

Sort:  

good article, I like to read it.diperbanyak more articles and continue to work, follow me @madimancity

Your contribution cannot be approved because it does not follow the Utopian Rules.

  • The format is not proper for approval.

You can contact us on Discord.
[utopian-moderator]