1 overview

This document mainly describes the deployment and application of Docker based on different Linux platforms.

2 background and value

Docker is an open source application container engine that allows developers to package their applications and dependencies into a lightweight, portable container that can then be published on any popular Linux machine, and can also be virtualized.

In this paper, docker is deployed on a number of different platforms, and portainer and swarm are used for cluster management. Flexible deployment, flexibility, status management, and monitoring of applications improve deployment efficiency and o&M capabilities.

3 Overall Plan

3.1 System Architecture

The system solution is shown in Figure 1. At the IaaS layer, raspberry PI, Ubuntu server and Feiten server form a LAN through switches. The PaaS layer is the Linux system of each server and docker deployed on it. The SaaS layer is for applications running on Docker.

3.2 Hardware Types and System Versions

Based on the current mature solutions, the chip type as shown in Table 1 is selected in this paper.

4 Technical Implementation

4.1 Docker Installation and Uninstallation

4.4.1 docker installation

A. Obtain environment information

Run lsb_release -a on Ubuntu, Raspbian, and Kylin to record the Codename value.

B. Download the ocker installation package

Login download.docker.com/linux/ combination query to the Codename value, enter the corresponding software package addresses, needs in the package list to select version to download.

C. Upload the Docker installation package to each server

Upload the software package downloaded in Step B (for example, to a USB flash drive) to the Ubuntu, Raspberryi, and FT2000/4 server folders, as shown in the following

D. Run the installation command

Screenshots of the installation process (using Ubuntu as an example)

After the installation is complete, run the docker -v command to query the Docker version. If the following command output (using Ubuntu as an example) is displayed, Docker is successfully installed.

E. Start Docker and set docker to start automatically

Run the following commands on all three servers (ubuntu is used as an example in the screenshot).

Systemctl enable docker # Set docker to start automatically upon startupCopy the code

As shown in the figure, Docker started successfully.

4.1.2 Docker uninstall

A. uninstall docker

sudo apt-get remove docker
sudo apt-get remove docker-engine docker.io
Copy the code

B. uninstall docker – ce

sudo apt-get remove docker-ce
Copy the code

C. Uninstall the installation dependencies

sudo apt-get autoremove --purge docker-ce
Copy the code

The preceding command does not remove any image, container, volume, or user-created configuration file. If you want to uninstall all images, containers, and volumes, run this command

rm -rf /var/lib/docker
Copy the code

Run the docker -v command. If the version cannot be queried, the uninstallation is successful.

4.2 Docker image packaging

Compile the Docker image

Dockerfile is a tool for compiling custom Docker. Dockerfile is a file without suffix, in which a series of operations such as basic image, runtime path of Docker and execution program are defined. This experiment is to package C++ program image based on ARM platform on the raspberry PI development board, and upload the image to the private warehouse in the LAN.

The following steps use Raspberrypi as an example to package the Docker image program. Enter the Raspberrypi command line and run the following command:

Mkdir docker # create a docker folder in the current directory CD docker # Create a CPP file in the docker folder vim wxmtest. CPP #  #include <iostream> using namespace std; int main () { cout << "hello-world" << endl; cout << "my first docker-----wxm" << endl; } Esc exits editing mode and enters: wq! saveCopy the code
Vim my_dockerfile # create a new dockerfile FROM GCC # build base image, download arm-gcc RUN mkdir -p /usr/myapp # Create docker workpath ADD lytest. CPP /usr/myapp # ADD source files to docker WORKDIR /usr/myapp RUN g++ lytest. CPP -o hello # compile CPP source file CMD ["./hello"] # execute.o executableCopy the code
Docker build -f./my_dockerfile -t xttest_docker:v1.0. Sudo Docker images # Check if the image you created existsCopy the code

Note: Here is a way to upload an image online:

Enter the website to register your own warehouse name and password, such as wangxueming66

Enter the username and password registered above, Sudo docker tag xttest_docker:v1.0 wangxueming66/ wXMtest_docker :v1.0 # Sudo docker push wangxueming66/ wXMtest_docker :v1.0 # Sudo docker pull wangxueming66/ wXMtest_docker :v1.0 # pull image, local or other hostCopy the code

4.2.2 Setting up a private warehouse

Docker warehouse is a place where Docker images are stored. Both official images and self-produced images need to be put into a warehouse for download. This experiment is based on the LOCAL area network, so the public warehouse based on the public network cannot be used, and the private warehouse based on the local area network should be built. Docker has officially provided private warehouse images, which can be used directly. A private repository runs on the management host Ubuntu. The process of setting up a private repository in Ubuntu is as follows:

A. Prepare a computer (Linux system) that can be connected to the Internet, deploy the Docker environment, and directly pull the Registry (private warehouse) image from the public warehouse:

sudo docker pull registry
Copy the code

B. Save the pulled image to the compressed file registry.tar:

Sudo docker save -o registry.tar Registry # registry.tar is the name of the local file to save, registry is the image nameCopy the code

C. Export the compressed file registry.tar to the disk of the Ubuntu management host on the LAN through a USB flash drive or other transmission media.

D. Load the compressed file registry. Tar on the management host to make it a local image:

Sudo docker load --input registry. Tar #Copy the code

E. Use sudo Docker images to check whether the Registry image exists

docker run -d -v /registry:/var/lib/registry -p 5000:5000 --restart=always --privileged=true --name registry Registry: Latest # Run the local imageCopy the code

If the execution succeeds, it means that our Docker private warehouse has been set up successfully. Part of this command is explained below:

  • / Registry represents the host directory, which is automatically created if it does not exist.
  • The purpose of doing this is to prevent the docker private warehouse when the container is deleted, the image in the warehouse will also be deleted. Docker-v host host directory: container directory
  • Finally, go to localhost:5000 to view the private repository. The private repository name is: localhost:5000, similar to the user name you created on docker.hub: wangxueming66

4.2.3 Uploading self-built Images to a Private Warehouse

Sections 4.2.1 and 4.2.2 already know how to build your own images and private repositories. This section will focus on how to upload your own images to private repositories.

Note: In this experiment, the management host Ubuntu IP is 192.168.5.. 112, so private warehouse name: 192.168.5.. 112:5000.

Take the Raspberrypi client node as an example. Create your own image on Raspberrypi and upload it to a private repository on the management host Ubuntu. The specific steps are as follows:

A. View the image name and select the ID or name of the image to be uploaded. The following uses xttest_docker: V1.0 as an example.

sudo docker images
Copy the code

B. Label the local mirror

Docker tag xttest_docker:v1.0 192.168.5.112:5000/ xttest_docker:v1.0Copy the code

C. Docker private repository server is based on HTTPS transfer by default, so we need to make relevant Settings to not use HTTPS transfer:

Use the vi /etc/docker/daemon.json file to save and exit. "Insecure -registries":["192.168.5.112:5000"] Finally looks like this: {" regime-mirrors ": (" https://njrds9qc.mirror.aliyuncs.com "), "insecure - registries:" [] "192.168.5.112:5000"}Copy the code

Restart Docker by executing the following two commands in sequence:

systemctl daemon-reload
systemctl restart docker
Copy the code

D. Run the image push command

Sudo docker push 192.168.5.112:5000/ xttest_docker:v1.0 #Copy the code

E. Check whether the mirror exists in the private repository.

The ls/registry/docker/registry/v2 / repositories 192.168.5.112 curl http:// : 5000 / v2 / _catalogCopy the code

If {” Repositories “:[“hello-world”]} is displayed, success is indicated.

4.2.4 Downloading a Docker Image to a Client

Download the image from the private repository using the client node FT2000/4 server on the LAN:

Sudo docker pull 192.168.5.112:5000/ xttest_docker:v1.0 #Copy the code

4.3. Use Portainer and swarm to build the cluster

Portainer is an open source lightweight managed UI that easily manages different Docker environments (Docker hosts or Swarm clusters).

This will install Potainer

A. Prepare a computer (Linux system) that can be connected to the Internet, deploy the Docker environment, and directly pull potainer (private warehouse) image from the public warehouse:

sudo docker pull potainer
Copy the code

B. Save the pulled image to the compressed file potainer.tar:

Sudo docker save -o potainer.tar potainer# potainer.tar is the name of the local file to save, and potainer is the image name.Copy the code

C. Export the potainer.tar file to the Ubuntu disk on the LOCAL area network (LAN) using a USB flash drive or other transmission media.

D. Load the compressed potainer.tar file to the management host to make it a local image:

Sudo docker load --input potainer.tarCopy the code

E. Run the sudo docker images command to check whether the Potainer image exists

Docker run - d - p - 9000-9000 restart = always - name prtainer - test docker. IO/portainer portainer # running local mirror, start potainer.Copy the code

F. Go to localhost:9000 to view the Potainer management interface, as shown in the following:

4.3.2 Build a cluster using Docker Swarm

Docker Swarm is Docker’s own native clustering solution for Docker containers, which has the advantage of being tightly integrated with the Docker ecosystem and using its own API. It monitors the number of containers across server clusters and is the most convenient way to create clustered Docker applications without additional hardware. It provides a small but useful choreography system for Dockerized applications. In this paper, Ubuntu server is selected as manager node, rasperrypi and FT2000 as worker1 and Worker2 nodes.

A. Create a swarm cluster

docker swarm init --advertise-addr <manager-IP>
Copy the code

  • The –advertise-addr option indicates the IP address advertised by the management node. Other nodes must be able to find the management node through this IP address.
  • The command output shows how to join the swarm cluster. Use the –token option to determine whether to join as a management node or a worker node.

B. Add nodes to the swarm cluster

Run the red part in 4.3.2.1 on the two worker nodes to join the cluster.

Note: If the join command cannot be found, run the docker swarm join-token worker command on the Manager node to retrieve the join command.

C. Run docker node ls to view node information

Run the docker node ls command on the Manager node to view cluster nodes:

D. Exit the cluster

The worker node executes docker swarm leave

The Manager node executes the Docker swarm leave –force command

4.3.3 Potainer Cluster Management

A. Add each node to the Portainer

It is necessary to set the listening of port 2375 on each Docker node in advance: Open configuration file/usr/lib/systemd/system/docker. The service or by systemctl status docker. The service command to check the docker. Service file path

Change the value of the configuration item ExecStart. If ExecStart does not have a value, add -h TCP ://0.0.0.0:2375. Otherwise, add the value after the existing parameter.

ExecStart = / usr/bin/dockerd -h TCP: / / 0.0.0.0:2375 - H fd: / / -- containerd = / run/containerd containerd. The sockCopy the code

Save the file and restart the Docker service

systemctl daemon-reload
systemctl restart docker
Copy the code

Note: You need to modify the configuration file above for all docker nodes. Log in to the Portal and choose Endpoints and Add Endpoint in the navigation tree.

According to the interface display, enter name (custom), endpoint URL (worker IP: 2375), Public IP (worker IP), and click “Add Endpoint”.

Choose Home in the navigation bar to view the added node.

B. Example of Potainer

On the home screen, set the address to localhost:9000 and click Ubuntu to view the running status of containers and clients.

You can view all the images and containers that exist on the management host and see the specific running status of the containers.

In the management host, there is a swarm management button, which can see all the nodes in the LAN.

Our nodes in the swarm management can add any container they want. Take ft2000/4 node as an example, we add one container.

After the container is created successfully, the running status of the container is displayed, and the running logs and status of the container are displayed.

5 concludes

The above process built for the entire Docker platform environment also encountered many holes in the middle, but they were solved one by one through the posts of myself, colleagues and netizens. Docker content there are many places to learn, and there will be more posts related to the content in the future, any questions are welcome to leave a message.

Time: 2021/7/9