Easily install Docker and run Docker swarm mode _docker

Source: Internet
Author: User
Tags docker ps docker hub docker swarm apache mesos

Profile

The biggest change in the Docker 1.12 version is the integration of Docker Swarm, which provides a engine model under Docker swarm, which is mainly about Docker swarm.

The Docker engine itself provides only container technology and does not solve container orchestration and communication in a clustered environment. Docker swarm is a container orchestration management tool, Docker-engine integrates Docker swarm after version 1.12 and does not need to be installed separately.

Docker swarm function, for example, there are 3 machines installed Docker environment, called 3 Docker nodes. So how do you manage these 3 Docker nodes and deploy the containers to these 3 nodes in a load-balanced pattern, and communicate with each other on different nodes? This time need to use the container choreography tool, the common choreography tool has the Google Open source Kubernetes, the Apache Mesos, Docker Company's Swarm.

As Google's Open-source tool, Kubernetes has been operating in Google's production environment for many years, with a rich and stable function, which is currently being used by many companies. Docker built the Swarm mode after version 1.12, integrating the container choreography into the Docker engine with the core components, and profiting from Kubernetes's successful experience.

Install Docker

Take Centos7 as an example, here is attached the official website installation document, Docker official website is too slow.
Using Yum Installation

1. Update yum source, sudo yum update;

2. Add the Docker Yum Warehouse

sudo tee/etc/yum.repos.d/docker.repo <<-' EOF '
[Dockerrepo]
name=docker Repository
Baseurl=https ://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https:// YUM.DOCKERPROJECT.ORG/GPG
EOF

3. Installation of Docker-engine,sudo yum install Docker-engine

4. Start the Docker daemon, sudo systemctl start docker
Docker installation to this end, said below in the company intranet environment through the agent installation Docker need to pay attention to the problem.

1. First let the machine through the proxy internet

Modify/etc/profile, add Export http_proxy= Proxy username: password @ proxy address: port

Make the changes take effect, source/etc/profile

2. Configure Yum Use agents

vim/etc/yum.conf Add proxy=http://Proxy username: password @ proxy address: port

After these two steps, you can install the Docker through the agent in the intranet.

Configure Docker

Open Docker remote management port 2375 and configure the Docker hub domestic warehouse.

1. New Docker configuration file

Vim/etc/sysconfig/docker

Increase

docker_opts= "-H unix:///var/run/docker.sock-h 0.0.0.0:2375--registry-mirror= domestic warehouse address"

If you need to access through proxy, you need to increase

http_proxy=http://Proxy Username: password @ proxy address: port

2. Load configuration file When starting the Docker daemon

Vim/lib/systemd/system/docker.servic

Modify Execstart configuration to

Execstart=/usr/bin/dockerd $DOCKER _opts

To increase configuration file paths in [Service]

Environmentfile=-/etc/sysconfig/docker

Specify the configuration file load path to the configuration file created in the first step/etc/sysconfig/docker

3. Restart the Docker daemon

sudo systemctl stop Docker
sudo systemctl start Docker

4. Check that the configuration is effective

Ps-ef|grep Docker

If the configuration takes effect, the dockerd process is followed by the parameters that have just been configured.

Start swarm mode

You only need to initialize the swarm cluster on one Docker node, and the other nodes join the cluster.

Select a Docker node as the swarm mode of leader, running

Docker swarm init--advertise-addr host IP

Follow the prompts to execute commands on other nodes join the Swarm cluster

Perform Docker node LS view node information on the leader node

Creating a cluster network

1. Run on any node in the Swarm cluster

Docker Network LS to view current network conditions

A network with a local scope can only be used for this computer, and the network under which the swarm cluster is created.

2. Run Docker network create--driver overlay my-network

Create a clustered network called My-network

Run Docker network LS again, you can see the my-network you just created, scope is swarm, this network can be used in swarm mode, and the containers on multiple nodes can be exchanged.

When you create a service in swarm, you can specify the network to use through the--network network name. Multiple service if you use the same scope as Swarm network, you can communicate with each other by the name of the service.

Docker swarm simple to use

Below a brief introduction to the use of Docker swarm, interested can view the Docker official documents for in-depth understanding.

The commands below are all running at the Swarm leader node!!

Docker Service Create--replicas 1--name tomcat--publish 9090:8080 tomcat:latest

This creates a service,swarm called Tomcat that encapsulates the container as a service, similar to the pod in Kubernates, and a service is a combination of containers available for swarm scheduling.

The--replicas 1 here Specifies the number of copies of the service.

--publish 9,090:8,080 publishes 8080 ports in the container to the host's 9090 port

Run Docker service LS look at the current list of services, and you can see a service called Tomcat.

Running Docker Service PS Tomcat can see which swarm node the Tomcat services are running on, and the status of the currently running.

Switch to the node where the Tomcat service runs, and run Docker PS to see the container ID and the port mapping.

Run the Docker logs-f container ID to view the Tomcat run log.

After Tomcat startup is successful, you can access the Tomcat home page in the browser, which is the IP of the Docker node (which can be any node), and the port is 9090, the publish specified when the service is created.

The top has successfully run a Tomcat service, which extends the deployment of this service.

Run the Docker service scale tomcat=2 to extend the Tomcat services to two instances.

Running Docker service LS can see that the replicas of Tomcat services becomes 1/2, and the second instance becomes 2/2 after the startup succeeds.

Run Docker service PS Tomcat to see which Docker node the two Tomcat service instances are running on, and the running state.

Swarm will automatically load balance in two service

Swarm there are other orders, such as the Docker service RM service name to delete the specified service, as well as grayscale publishing, etc., please refer to the official documents, no longer detailed here.

Problems needing attention in swarm mode

Swarm only schedules the container between the Docker nodes and does not dispatch the mount volume volume the container uses. When you deploy a container for a database with swarm, you need to be aware of the problem with the data file. or the container that loads the external configuration file, you also need to be aware of the configuration file problem.
A simple workaround is to have these containers be dispatched to the same Docker node at a time. You need to specify the--constraint parameter when creating the service, such as--constraint ' node.hostname==myhost ', so that the service created will only be dispatched to the Docker node with the host name Myhost.
Another way to solve this problem is to use Docker volume plug-ins, such as Flocker. Flocker can be in the container scheduling, together with volume dispatch, here no longer elaborate, you can refer to Flocker's official website documents.

At last

This is just a brief introduction to the installation configuration of Docker and the use of Docker swarm, to get a better understanding, please refer to the official documentation, the official document is the best way to learn. Docker is just the opening of a micro-service architecture, and Docker essential to the practice of micro-service.

Following the introduction of the Docker deployment based micro-service architecture, using the spring cloud as a micro-service solution, based on Docker MySQL and MongoDB deployments, Docker based RABBITMQ and ACTIVEMQ messaging middleware deployment, And Kafka, Elk Log Collection statistics based on Docker deployment.

The above is a small set to introduce the easy installation Docker and run Docker swarm mode, I hope to help you, if you have any questions please give me a message, small series will promptly reply to everyone. Here also thank you very much for the cloud Habitat Community website support!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.