Webアプリケーションを起動してWebアプリケーションにアクセスできるドッキングファイルを作成しています。これには、オリジナルのdocker-compose-dev.yml
ファイルのcomposeコマンドを使用します。composeからswarmへ: '読み取り許可パケット'でMySQLサーバーとの接続が切断されました
version: "3"
services:
learnintouch-startup:
image: localhost:5000/learnintouch-startup
container_name: learnintouch-startup
restart: always
volumes:
- "~/dev/docker/projects/learnintouch/volumes/engine:/usr/bin/learnintouch/engine"
- "~/dev/docker/projects/learnintouch/volumes/www.learnintouch/account/data:/usr/bin/learnintouch/www/learnintouch.com/account/data"
- "~/dev/docker/projects/learnintouch/volumes/www.thalasoft/account/data:/usr/bin/learnintouch/www/thalasoft.com/account/data"
- "~/dev/docker/projects/learnintouch/volumes/www.folkuniversitet/account/data:/usr/bin/learnintouch/www/folkuniversitet/account/data"
ports:
- "81:80"
links:
- mysql
- redis
- nodejs-learnintouch
nodejs-learnintouch:
image: localhost:5000/nodejs-learnintouch
container_name: nodejs-learnintouch
restart: always
volumes:
- "~/dev/docker/projects/learnintouch/volumes/engine:/usr/bin/learnintouch/engine"
ports:
- "9001:9001"
links:
- redis
mysql:
image: localhost:5000/mysql:5.6.30
container_name: mysql
restart: always
environment:
- MYSQL_ROOT_PASSWORD=root
volumes:
- "~/dev/docker/projects/learnintouch/volumes/mysql/data:/usr/bin/mysql/install/data"
redis:
image: localhost:5000/redis:3.0.7
container_name: redis
restart: always
ここでは、代わりにスウォームモードで実行したいと考えています。私は、エンジンとクライアントの両方についてドッカーのバージョン17.05.0-ce
を実行しているので、swarmモードが利用可能であることを理解しています。ホストはUbuntu 16.04
です。
私はdocker swarm init
コマンドですべての権限を起動できました。
それから私は、Webアプリケーションを起動しよう:
$ docker stack deploy --compose-file docker-compose-swarm-dev.yml learnintouch
Creating network learnintouch_default
Creating service learnintouch_mysql
Creating service learnintouch_redis
Creating service learnintouch_learnintouch-startup
Creating service learnintouch_nodejs-learnintouch
learnintouch-startup
コンテナは、MySQLクライアントがmysql
コンテナにMySQLサーバにアクセスしようとしています。
しかし、このようなコンテナ名は存在せず、そのようなホスト名もありません。
非集団モードでは、以前はコンテナ名がホスト名として使用されていましたが、そのようなコンテナ名はありません。
私はdocker-compose-swarm-dev.yml
ファイルに次docker stack deploy --compose-file docker-compose-swarm-dev.yml learnintouch
コマンドを使用してみました:
version: "3"
services:
learnintouch-startup:
image: localhost:5000/learnintouch-startup
volumes:
- "~/dev/docker/projects/learnintouch/volumes/engine:/usr/bin/learnintouch/engine"
- "~/dev/docker/projects/learnintouch/volumes/www.learnintouch/account/data:/usr/bin/learnintouch/www/learnintouch.com/account/data"
- "~/dev/docker/projects/learnintouch/volumes/www.thalasoft/account/data:/usr/bin/learnintouch/www/thalasoft.com/account/data"
- "~/dev/docker/projects/learnintouch/volumes/www.folkuniversitet/account/data:/usr/bin/learnintouch/www/folkuniversitet/account/data"
ports:
- "81:80"
nodejs-learnintouch:
image: localhost:5000/nodejs-learnintouch
volumes:
- "~/dev/docker/projects/learnintouch/volumes/engine:/usr/bin/learnintouch/engine"
ports:
- "9001:9001"
mysql:
image: localhost:5000/mysql:5.6.30
environment:
- MYSQL_ROOT_PASSWORD=root
volumes:
- "~/dev/docker/projects/learnintouch/volumes/mysql/data:/usr/bin/mysql/install/data"
hostname: mysql
redis:
image: localhost:5000/redis:3.0.7
をどのように群れサービスのホスト名を指定することができますか?
docker-compose -f docker-compose-dev.yml up -d
コマンドを使用して非集団モードでアプリケーションを起動すると、アプリケーションが正常に応答することに注意してください。私がdocker stack deploy --compose-file docker-compose-swarm-dev.yml learnintouch
コマンドを使用してmysql
ホスト名が見つからない場合は、The data source for the database db_learnintouch could not be initialized for the user learnintouch on the host mysql:3306
というコマンドを使用して起動してください。実際、後者の場合、コンテナ名はmysql
ではなくlearnintouch_mysql.1.pu846rr8to5gwxwnxpdm4hdth
です。
UPDATE:問題はホスト名ではなく、swarm/mysqlであるようです。
$ docker exec -it learnintouch_mysql.1.m51o8deg8cslb8mzayp119m67 bash
[email protected]:/usr/bin/mysql-5.6.30# cd /usr/bin/mysql/install;
[email protected]:/usr/bin/mysql/install# bin/mysql --protocol=tcp -h mysql -P 3306 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
しかしlearnintouch-startup
クライアントコンテナでは、私はそれにログインmysql
サービスにpingを実行できませんが:私はちょうど罰金のMySQLにログインすることができますmysql
容器に
$ docker exec -it learnintouch_learnintouch-startup.1.kf13qktlvxs9rgjzaea2xxd68 bash
[email protected]:/usr/bin/learnintouch/www/folkuniversitet# cd /usr/bin/mysql/install
[email protected]:/usr/bin/mysql/install# bin/mysql --protocol=tcp -h mysql -P 3306 -u root -p
Enter password:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0
[email protected]:/usr/bin/mysql/install# ping mysql
PING mysql (10.0.0.8) 56(84) bytes of data.
64 bytes from 10.0.0.8: icmp_seq=1 ttl=64 time=0.061 ms
64 bytes from 10.0.0.8: icmp_seq=2 ttl=64 time=0.084 ms
64 bytes from 10.0.0.8: icmp_seq=3 ttl=64 time=0.075 ms
^C
--- mysql ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1998ms
私ができますまた、実際にtelnetで接続:と5.6.30:私はMySQLのバージョンのMySQL構築されたカスタムを使用してい
[email protected]:/usr/bin/learnintouch/www/folkuniversitet# telnet mysql 3306
Trying 10.0.0.6...
Connected to mysql.
Escape character is '^]'.
N
5.6.30-logs5L\i|Sj��=0t}62:k,8s]mysql_native_password
!#08S01Got packets out of orderConnection closed by foreign host.
を0ファイル:
[mysqld]
bind-address = 0.0.0.0 # Allow client binding from any IP address instead of just 127.0.0.1
port = 3306
sql_mode = NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION # This is strict mode: NO_ENGINE_SUBSTITUTION,STRICT_TRANS_TABLES
socket = /usr/bin/mysql/install/tmp/mysql.sock
user = root
basedir = /usr/bin/mysql/install
datadir = /usr/bin/mysql/install/data
log-bin = /usr/bin/mysql/install/mysql.bin.log
log-error = /usr/bin/mysql/install/mysql.error.log
general-log-file = /usr/bin/mysql/install/mysql.log
slow-query-log-file = /usr/bin/mysql/install/mysql.slow.queries.log
innodb_file_per_table = 1
innodb_flush_log_at_trx_commit = 1
sync_binlog = 1
innodb_flush_method = O_DIRECT
character-set-server = utf8mb4
collation-server = utf8mb4_unicode_ci
init-connect = 'SET NAMES utf8mb4'
character-set-client-handshake = FALSE
connect_timeout = 60
wait_timeout = 28800 # amount of seconds during inactivity that MySQL will wait before it will close a connection on a non-interactive connection
interactive_timeout = 28800 # same, but for interactive sessions
[client]
socket = /usr/bin/mysql/install/tmp/mysql.sock
default-character-set = utf8mb4
[mysql]
default-character-set = utf8mb4
protocol = tcp # Forces the client to use the TCP protocol, except for PHP which ignores it
mysql
コンテナには/etc/hosts.allow
も/etc/hosts.deny
ファイルはありません。
ファイアウォールはありません。
ドッカーのバージョンはエンジンとクライアントの両方で17.05.0-ceであり、ドッカーの作成バージョンは1.16.1です。
更新:swarmを削除してもう一度起動したら、ブラウザでアプリケーションを実行して正常に動作することがわかりました。そして、これに続いて、別の削除を続けて開始し、再び、同じエラーが発生しました。だから、時々、エラーは起こりません。
更新:クライアントコンテナ内からtelnet mysql 3306
コマンドを実行すると、問題が削除され、MySQLクライアント接続が続行されます。これは一貫しています:私はswarmを削除して新たに起動します。クライアントコンテナにbashをオープンし、MySQLサーバコンテナにログインしようとすると失敗します。何度も再試行して、同じことをすべて失敗します。ping mysql
コマンドを実行してから何度も接続を試みて失敗すると、telnet mysql 3306
コマンドを実行して接続しようとすると成功します。ここで
[email protected]:/usr/bin/mysql/install# cd /usr/bin/mysql/install; bin/mysql --protocol=tcp -h mysql -P 3306 -u root -p
Enter password:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0
[email protected]:/usr/bin/mysql/install#
[email protected]:/usr/bin/mysql/install# ping mysql
PING mysql (10.0.0.4) 56(84) bytes of data.
64 bytes from 10.0.0.4: icmp_seq=1 ttl=64 time=0.088 ms
64 bytes from 10.0.0.4: icmp_seq=2 ttl=64 time=0.109 ms
64 bytes from 10.0.0.4: icmp_seq=3 ttl=64 time=0.091 ms
^C
--- mysql ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 1999ms
rtt min/avg/max/mdev = 0.088/0.096/0.109/0.009 ms
[email protected]:/usr/bin/mysql/install# telnet mysql 3306
Trying 10.0.0.4...
Connected to mysql.
Escape character is '^]'.
N
5.6.30-logf[tT)mlX��[email protected]\SkBmysql_native_password
Connection closed by foreign host.
[email protected]:/usr/bin/mysql/install# cd /usr/bin/mysql/install; bin/mysql --protocol=tcp -h mysql -P 3306 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
は完全なデモが証拠として実行されます。
$ docker exec -it learnintouch_learnintouch-startup.1.ili3m1kre9q2eaiyzlucr2uot bash
[email protected]:/usr/bin/learnintouch/www/folkuniversitet# cd /usr/bin/mysql/install; bin/mysql --protocol=tcp -h mysql -P 3306 -u root -pEnter password:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0
[email protected]:/usr/bin/mysql/install#
[email protected]:/usr/bin/mysql/install#
[email protected]:/usr/bin/mysql/install# ping mysql
PING mysql (10.0.0.4) 56(84) bytes of data.
64 bytes from 10.0.0.4: icmp_seq=1 ttl=64 time=0.040 ms
64 bytes from 10.0.0.4: icmp_seq=2 ttl=64 time=0.110 ms
64 bytes from 10.0.0.4: icmp_seq=3 ttl=64 time=0.093 ms
64 bytes from 10.0.0.4: icmp_seq=4 ttl=64 time=0.091 ms
^C
--- mysql ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 2999ms
rtt min/avg/max/mdev = 0.040/0.083/0.110/0.027 ms
[email protected]:/usr/bin/mysql/install# bin/mysql --protocol=tcp -h mysql -P 3306 -u root -p
Enter password:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0
[email protected]:/usr/bin/mysql/install# bin/mysql --protocol=tcp -h mysql -P 3306 -u root -p
Enter password:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0
[email protected]:/usr/bin/mysql/install# ping mysql
PING mysql (10.0.0.4) 56(84) bytes of data.
64 bytes from 10.0.0.4: icmp_seq=1 ttl=64 time=0.091 ms
64 bytes from 10.0.0.4: icmp_seq=2 ttl=64 time=0.105 ms
64 bytes from 10.0.0.4: icmp_seq=3 ttl=64 time=0.082 ms
^C
--- mysql ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.082/0.092/0.105/0.014 ms
[email protected]:/usr/bin/mysql/install# bin/mysql --protocol=tcp -h mysql -P 3306 -u root -p
Enter password:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0
[email protected]:/usr/bin/mysql/install# bin/mysql --protocol=tcp -h mysql -P 3306 -u root -p
Enter password:
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading authorization packet', system error: 0
[email protected]:/usr/bin/mysql/install# telnet mysql 3306
Trying 10.0.0.4...
Connected to mysql.
Escape character is '^]'.
N
5.6.30-logZo?*[email protected])M��(~cWg"q5R}?amysql_native_password
^CConnection closed by foreign host.
[email protected]:/usr/bin/mysql/install# bin/mysql --protocol=tcp -h mysql -P 3306 -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.6.30-log Source distribution
Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> quit;
Bye
[email protected]:/usr/bin/mysql/install#
どのように 'docker ps'コマンドが私のMySQLサービスの異なるランダム化されたコンテナ名を表示するのですか?私は 'mysql'のホスト名を持つ必要があるので、' mysql'のコンテナ名を持つ必要があると思います。私は私の質問に段落を追加しました。 – Stephane
これをスタックにデプロイすると、コンテナがサービスによって実行されるため、サービスは既知のcontainer_nameでコンテナをデプロイします。特定のサービスを3でスケーリングすると、サービスはその下に3つのコンテナを配置します。サービス名 – Vignajeth
を使ってのみ行うことができます。どうすれば私のMySQLサービスをホスト名 'mysql'で公開することができますか?それは私の質問のタイトルです:-) – Stephane