Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create mysql service on swarm manager

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces the knowledge of "how to create mysql service on swarm manager". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

Create overlay network vincent@swarm-manager:~$ docker network create-d overlay demo3jgzsg1gt3gxb1u1i3l7rgqdi

Take a look at the overlay network that does add demo:

Vincent@swarm-manager:~$ docker network lsNETWORK ID NAME DRIVER SCOPE1273b71b09c8 bridge bridge local3jgzsg1gt3gx demo overlay swarm0d41041dafaa docker_gwbridge bridge local8212167bd2d1 host host localmu4mlqqsl2a3 ingress overlay Swarm089cabdcfa5a none null local

Let's take a look at the network in swarm-worker1:

Vincent@swarm-worker-1:~$ docker network lsNETWORK ID NAME DRIVER SCOPE16524b38199c bridge bridge local727b01e93cc6 docker_gwbridge bridge locald156bf01fbb9 host host localmu4mlqqsl2a3 ingress overlay swarm27d89fbc2a96 none null local

At present, the network of demo has not been found in swarm-worker1, so don't worry, just keep going.

Create a mysql service on swarm manager with the following command:

Vincent@swarm-manager:~$ docker service create-name mysql--env MYSQL_ROOT_PASSWORD=123456-env MYSQL_DATABASE=wordpress-network demo-mount type=volume,source=mysql-data,destination=/var/lib/mysql mysql:5.7

Creating a service is slightly different from the previous creation of container, using the-v option and replacing it with-- mount type=, source, destination,-e, and now-- env.

The commands of docker service create and docker run are basically the same. Instead of using docker run under swarm, docker run creates a container locally. The docker container we created under cluster does not necessarily run under that machine. So docker run is basically out of use.

Vincent@swarm-manager:~$ docker service create-- name mysql--env MYSQL_ROOT_PASSWORD=123456-- env MYSQL_DATABASE=wordpress-- network demo-- mount type=volume,source=mysql-data,destination=/var/lib/mysql mysql:5.7s4rgbf3mfyifbobpzf1zhnm1ooverall progress: 1 out of 1 tasks 1 tasks 1: running [= = >] verify: Service converged

The first time running is a little slow and requires patience and so on.

View the mysql service you just created:

Vincent@swarm-manager:~$ docker service ps mysqlID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTStslzqwo3t7ag mysql.1 mysql:5.7 swarm-worker1 Running Running about a minute ago

You can see that the mysql service is running on the swarm-worker1 node, confirming on swarm-worker1:

Vincent@swarm-worker1:~$ docker container lsCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES57ec905ddae0 mysql:5.7 "docker-entrypoint.s..." 4 minutes ago Up 4 minutes 3306/tcp, 33060/tcp mysql.1.tslzqwo3t7ag9kppit3wv3ixi

You can see that this service does exist on swarm-worker1.

Create a wordpress service on swarm manager with the following command:

Vincent@swarm-manager:~$ docker service create-name wordpress-p 80:80-env WORDPRESS_DB_PASSWORD=123456-env WORDPRESS_DB_HOST=mysql-network demo wordpress

Port 80 of wordpress's web service needs to be mapped to port 80 of the external environment:

Vincent@swarm-manager:~$ docker service create-- name wordpress-p 80:80-- env WORDPRESS_DB_PASSWORD=123456-- env WORDPRESS_DB_HOST=mysql-- network demo wordpress6o6q9bz3da7gll63syhsuudq6overall progress: 1 out of 1 tasks 1 tasks 1: running [= = >] verify: Service convergedvincent@swarm-manager:~$ docker service ps wordpressID NAME IMAGE NODE DESIRED STATE CURRENT STATE ERROR PORTSqclnrwt9aj7v wordpress.1 wordpress:latest swarm-manager Running Running 39 seconds ago iie4bu@hostdocker:~$

You can see that wordpress ends up running on the swarm-manager node:

Vincent@swarm-manager:~$ docker container lsCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES615f80f418e7 wordpress:latest "docker-entrypoint.s..." 2 minutes ago Up 2 minutes 80/tcp wordpress.1.qclnrwt9aj7voog129juf1kss

Next, we are going to access the wordpress service. We have exposed the port to port 80. Check that the IP address of swarm-manager is 192.168.152.45.

Visit 192.168.152.45 successfully!

Look at the demo network on swarm-manager, and the content in container is as follows:

"Containers": {"b2a8fc394934297364b0f4468e83928d914f0b154ac1dbb027d7c787def6bb8b": {"Name": "wordpress.1.2qaocpzdv0kg0v59nd1img2hk", "EndpointID": "422acc517ee8ddafed7a6a439aefd867a54d896f609327eb2d53e348e9510d30", "MacAddress": "02:42:0a:00:01:13", "IPv4Address": "10.0.1.19Comp24" "IPv6Address": "}}

Look at the demo network on swarm-worker1, and the content in container is as follows:

"2a21ab0bfd6afb1d8b850660eccf68f8b8728d4fb72f6a40572d3c87b9618018": {"Name": "mysql.1.a4uhjsjt25sj2df39t2dfi9va", "EndpointID": "2ade77f2074c5009c62fa70841dcdc999bd30c7d129d5789ac31740b44949006", "MacAddress": "02:42:0a:00:01:11", "IPv4Address": "10.0.1.17 IPv4Address", "IPv6Address": ""}

The interesting thing is: when we visit swarm-worker1 's ip, the wordpress page also appears! The reasons are explained in detail in the following section.

We created an overlay network on swarm-manager before we created mysql and wordpress. You don't see the network you just created on swarm-worker1 and swarm-worker2. After we have created the service, we see the created network on swarm-worker2. This is one of the mechanisms of swarm. Because when a service is assigned to a node, in order to maintain communication with the swarm-manager, the overlay network must be synchronized.

As we said before when talking about docker's multi-machine network, multi-machine overlay network uses the etcd tool, which is not needed in swarm mode, because the underlying mechanism of swarm is to synchronize the creation of the network, because multiple containers need to communicate synchronously through the overlay network.

This is the end of "how to create mysql service on swarm manager". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report