Docker Container Deployment Consul cluster
First, Docker installation and start-up
1.1 Installing Docker
[Email protected]/]# yum-y install Docker-io
1.2 Changing the configuration file
[Email protected]/]# vi/etc/sysconfig/docker
Other-args column changed to: other_args= "--exec-driver=lxc--selinux-enabled"
1.3 Launching the Docker service
[[email protected]/]# service Docker start
Starting cgconfig service: [OK]
Starting Docker: [OK]
1.4 Adding Docker to boot
[[email protected]/]# chkconfig Docker on
1.5 Basic Information view
Docker version: View the release number of Docker, including client, server, dependent go, etc.
[[email protected]/]# Docker version
Client version:1.0.0
Client API version:1.12
Go version (client): go1.2.2
Git commit (client): 63fe64c/1.0.0
Server version:1.0.0
Server API version:1.12
Go version (server): go1.2.2
Git commit (server): 63fe64c/1.0.0
Docker Info: View System (Docker) level information, including managed images, containers number, etc.
[Email protected]/]#Docker Info
containers:16
images:40
Storage Driver:devicemapper
Pool Name:docker-253:0-1183580-pool
Data file:/var/lib/docker/devicemapper/devicemapper/data
Metadata file:/var/lib/docker/devicemapper/devicemapper/metadata
Data Space used:2180.4 Mb
Data Space total:102400.0 Mb
Metadata Space used:3.4 Mb
Metadata Space total:2048.0 Mb
Execution driver:lxc-0.9.0
Kernel version:2.6.32-431.el6.x86_64
Second, Progrium/consul image installation
2.1 Searching for Mirrors
[Email protected]/]# Docker search Consul
Docker.io Docker.io/progrium/consul 231 [OK]
Docker.io Docker.io/gliderlabs/consul [OK]
......
2.2 Download Image Progrium/consul
[Email protected]/]# Docker pull Docker.io/progrium/consul
2.3 Viewing Mirrors
[[email protected]/]# Docker images-a ////list all images (including history)
Third, start the consul Agent in the Docker container, the operation here refer to Progrium/consul's official instructions https://hub.docker.com/r/progrium/consul/
3.1 Starting an agent in a container in server mode
[Email protected]/]# Docker run-p 8400:8400-p 8500:8500-p 8600:53/udp-h node1 progrium/consul-server- Bootstrap
We test that the HTTP port can be accessed via curl:
[Email protected]/]# Curl Localhost:8500/v1/catalog/nodes
To test again, you can also access the DNS port via dig:
[Email protected]/]# dig @0.0.0.0-p 8600 Node1.node.consul
3.2 Launching the consul cluster with a Docker container
Start three server nodes separately and bind to the same IP
-bootstrap-expect: The number of server nodes that are expected to be provided in a datacenter, and when this value is provided, consul waits until the specified number of sever is reached to boot the entire cluster
[Email protected]/]#Docker run-d--name node1 -H node1 progrium/consul-server-bootstrap-expect 3
[Email protected]/]#join_ip= "$ (Docker inspect-f ' {{. Networksettings.ipaddress}} ' node1) ' ////Get the IP address of Node1
[Email protected]/]#Docker run-d--name node2 -H node2 progrium/consul-server-join $JOIN _ip
[Email protected]/]#Docker run-d--name node3 -H node3 progrium/consul-server-join $JOIN _ip
Start the client node
[Email protected]/]#Docker run-d-P 8400:8400-p 8500:8500-p 8600:53/udp--name node4 -H node4 Progrium/consul-join $ Join_ip
At this point, use the Nsenter tool to connect to Node1 run Consul info, can go to node1 for state = Leader
To view a running container
[[email protected]/]# Docker PS
View all containers (running and closed)
[email protected]/]# Docker ps-a
Remove all containers
[[email protected]/]# Docker RM $ (Docker ps-a-Q)
3.3 Entering Docker container operation view
When Docker uses the-d parameter, it enters the background when the container is started.
Sometimes you need to go into the container to operate, especially when testing. There are many ways to do this, including using the Ssh,docker attach command or the Nsenter tool.
3.3.1 using Docker attach, multiple windows are inconvenient
[email protected]/]# Docker attach Node3
2016/03/14 03:35:40 [INFO] agent:synced service ' consul '
3.3.2 Using Nsenter
Install first
[Email protected]/]# cd/tmp
[Email protected]/]# Curl https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.gz
[Email protected]/]# tar zxf util-linux-2.24.tar.gz
[Email protected]/]# CD util-linux-2.24
[Email protected]/]#/configure--without-ncurses
[email protected]/]# make Nsenter
[[email protected]/]# CP nsenter/usr/local/bin ////do not use make install, directly to the nsenter copy to the/usr/local/bin directory
[[email protected]/]# pid= ' docker inspect--format ' {{. State.pid}} "Node1"
[Email protected]/]# nsenter--target $PID--mount--uts--ipc--net--pid
The above 2 commands can be in one: Nsenter--target ' docker inspect--format ' {{. State.pid}} "Node1 '--mount--uts--ipc--net--pid
node1:/# ////ok You can enter the Linux command to check the look, such as
Start Consul Command
node1:/# Consul Members
node1:/# Consul Info
Docker Container Deployment Consul cluster