mysql - Docker:连接到 mysql 时遇到问题,网络问题?

标签 mysql wordpress docker docker-compose docker-container

我有一个带有持久卷的 WordPress 和 MySQL 容器。我一直在尝试学习 docker,并且在这个过程中错误地删除了旧的 docker-compose.yml 和除 mysql 卷之外的所有内容。我现在已经尽我所能将它重新创建到撰写文件中,但是每当我启动机器时,它都无法连接到 MySQL 服务器。谁能指出我哪里出错了。

我怀疑两者之间的联系有问题,但我不确定。

docker-compose.yml:

version: '2'

services:

  wp.spm:
    restart: always
    image: wordpress:latest
    ports:
      - "8080:80"
    environment:
      WORDPRESS_DB_HOST: localhost:3306
      WORDPRESS_DB_USER: spm
      WORDPRESS_DB_PASSWORD: Ivietoo2Phah8xay
      WORDPRESS_DB_NAME: spm
    links:
      - mysql.5.7
    working_dir: /var/www/html
    volumes:
      - ./wp-content:/var/www/html/wp-content

  mysql.5.7:
    restart: always
    image: mysql:5.7
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: root # TODO: Change this
      MYSQL_USER: spm
      MYSQL_PASS: Ivietoo2Phah8xay
      MYSQL_DATABASE: spm
    volumes:
      - db_data:/var/lib/mysql

volumes:
  db_data:

日志:

$ docker-compose up
Pulling mysql.5.7 (mysql:5.7)...
5.7: Pulling from library/mysql
75a822cd7888: Pull complete
b8d5846e536a: Pull complete
b75e9152a170: Pull complete
832e6b030496: Pull complete
fe4a6c835905: Pull complete
c3f247e29ab1: Pull complete
21be3e562071: Pull complete
c7399d6bf033: Pull complete
ccdaeae6c735: Pull complete
713c7d65b0d3: Pull complete
86c18539deb2: Pull complete
Digest: sha256:9ef4478a3aa597f59b2266d5702f55f29acc468b5bf3518c3c90cbca4e243823
Status: Downloaded newer image for mysql:5.7
Pulling wp.spm (wordpress:latest)...
latest: Pulling from library/wordpress
75a822cd7888: Already exists
e4d8a4e038be: Pull complete
81d4d961577a: Pull complete
f0a3d7c702e3: Pull complete
a4b7d2c4c9cc: Pull complete
de3fbbff60a9: Pull complete
336c38203cc2: Pull complete
628c443fd26f: Pull complete
6b43451e2e60: Pull complete
a4dc6da381e6: Pull complete
771a9ee2bb6a: Pull complete
3862c25af8ee: Pull complete
a3bf90f1df74: Pull complete
4564f4870a3e: Pull complete
ec9c03f98075: Pull complete
5f4dfa2bfbb4: Pull complete
69feb6fb40db: Pull complete
5f129a65fac7: Pull complete
Digest: sha256:0bb659eafa22cdb9f14bc05d17be97132842eb122eb8ff346ecafe7553f48f22
Status: Downloaded newer image for wordpress:latest
Creating googleserver_mysql.5.7_1
Creating googleserver_wp.spm_1
Attaching to googleserver_mysql.5.7_1, googleserver_wp.spm_1
mysql.5.7_1  | 2017-01-09T11:07:44.271254Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
mysql.5.7_1  | 2017-01-09T11:07:44.278843Z 0 [Note] mysqld (mysqld 5.7.17) starting as process 1 ...
wp.spm_1     | WordPress not found in /var/www/html - copying now...
mysql.5.7_1  | 2017-01-09T11:07:44.347784Z 0 [Note] InnoDB: PUNCH HOLE support available
mysql.5.7_1  | 2017-01-09T11:07:44.347937Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
mysql.5.7_1  | 2017-01-09T11:07:44.347956Z 0 [Note] InnoDB: Uses event mutexes
mysql.5.7_1  | 2017-01-09T11:07:44.348024Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
mysql.5.7_1  | 2017-01-09T11:07:44.348048Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.3
mysql.5.7_1  | 2017-01-09T11:07:44.348060Z 0 [Note] InnoDB: Using Linux native AIO
mysql.5.7_1  | 2017-01-09T11:07:44.356631Z 0 [Note] InnoDB: Number of pools: 1
mysql.5.7_1  | 2017-01-09T11:07:44.367564Z 0 [Note] InnoDB: Using CPU crc32 instructions
mysql.5.7_1  | 2017-01-09T11:07:44.370949Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
mysql.5.7_1  | 2017-01-09T11:07:44.419506Z 0 [Note] InnoDB: Completed initialization of buffer pool
mysql.5.7_1  | 2017-01-09T11:07:44.476953Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
mysql.5.7_1  | 2017-01-09T11:07:44.501029Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
wp.spm_1     | WARNING: /var/www/html is not empty - press Ctrl+C now if this is an error!
wp.spm_1     | + ls -A
wp.spm_1     | wp-content
wp.spm_1     | + sleep 10
mysql.5.7_1  | 2017-01-09T11:07:44.614777Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
mysql.5.7_1  | 2017-01-09T11:07:44.615567Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
mysql.5.7_1  | 2017-01-09T11:07:45.135167Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
mysql.5.7_1  | 2017-01-09T11:07:45.137285Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
mysql.5.7_1  | 2017-01-09T11:07:45.137414Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
mysql.5.7_1  | 2017-01-09T11:07:45.138586Z 0 [Note] InnoDB: Waiting for purge to start
mysql.5.7_1  | 2017-01-09T11:07:45.189557Z 0 [Note] InnoDB: 5.7.17 started; log sequence number 12168868
mysql.5.7_1  | 2017-01-09T11:07:45.194278Z 0 [Note] Plugin 'FEDERATED' is disabled.
mysql.5.7_1  | 2017-01-09T11:07:45.195063Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
mysql.5.7_1  | 2017-01-09T11:07:45.223753Z 0 [Note] InnoDB: Buffer pool(s) load completed at 170109 11:07:45
mysql.5.7_1  | 2017-01-09T11:07:45.235736Z 0 [Warning] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
mysql.5.7_1  | 2017-01-09T11:07:45.237375Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
mysql.5.7_1  | 2017-01-09T11:07:45.237759Z 0 [Note] IPv6 is available.
mysql.5.7_1  | 2017-01-09T11:07:45.237877Z 0 [Note]   - '::' resolves to '::';
mysql.5.7_1  | 2017-01-09T11:07:45.237961Z 0 [Note] Server socket created on IP: '::'.
mysql.5.7_1  | 2017-01-09T11:07:45.295529Z 0 [Warning] 'db' entry 'sys mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql.5.7_1  | 2017-01-09T11:07:45.296334Z 0 [Warning] 'proxies_priv' entry '@ root@localhost' ignored in --skip-name-resolve mode.
mysql.5.7_1  | 2017-01-09T11:07:45.304463Z 0 [Warning] 'tables_priv' entry 'sys_config mysql.sys@localhost' ignored in --skip-name-resolve mode.
mysql.5.7_1  | 2017-01-09T11:07:45.325375Z 0 [Note] Event Scheduler: Loaded 0 events
mysql.5.7_1  | 2017-01-09T11:07:45.326559Z 0 [Note] Executing 'SELECT * FROM INFORMATION_SCHEMA.TABLES;' to get a list of tables using the deprecated partition engine. You may use the startup option '--disable-partition-engine-check' to skip this check. 
mysql.5.7_1  | 2017-01-09T11:07:45.326653Z 0 [Note] Beginning of list of non-natively partitioned tables
mysql.5.7_1  | 2017-01-09T11:07:45.377612Z 0 [Note] End of list of non-natively partitioned tables
mysql.5.7_1  | 2017-01-09T11:07:45.378560Z 0 [Note] mysqld: ready for connections.
mysql.5.7_1  | Version: '5.7.17'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
wp.spm_1     | Complete! WordPress has been successfully copied to /var/www/html
wp.spm_1     | 
wp.spm_1     | Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in - on line 19
wp.spm_1     | 
wp.spm_1     | MySQL Connection Error: (2002) No such file or directory
wp.spm_1     | 
wp.spm_1     | Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in - on line 19
wp.spm_1     | 
wp.spm_1     | MySQL Connection Error: (2002) No such file or directory

最佳答案

我会说问题是您将 wp 实例与本地主机中设置的数据库链接起来,但事实并非如此,因为您的数据库位于服务器 mysql.5.7 中。我会尝试下一个 yaml 文件:

version: '2'

services:

  wp.spm:
    restart: always
    image: wordpress:latest
    ports:
      - "8080:80"
    environment:
      WORDPRESS_DB_HOST: mysql.5.7:3306
      WORDPRESS_DB_USER: spm
      WORDPRESS_DB_PASSWORD: Ivietoo2Phah8xay
      WORDPRESS_DB_NAME: spm
    depends_on:
      - mysql.5.7
    working_dir: /var/www/html
    volumes:
      - ./wp-content:/var/www/html/wp-content

  mysql.5.7:
    restart: always
    image: mysql:5.7
    ports:
      - 3306:3306
    environment:
      MYSQL_ROOT_PASSWORD: root # TODO: Change this
      MYSQL_USER: spm
      MYSQL_PASS: Ivietoo2Phah8xay
      MYSQL_DATABASE: spm
    volumes:
      - db_data:/var/lib/mysql

volumes:
  db_data:

关于mysql - Docker:连接到 mysql 时遇到问题,网络问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41546766/

相关文章:

mysql - 如何在远程计算机上创建类似的表

php - 更改自定义帖子类型的 WP 管理员帖子状态过滤器

css - Wordpress - 根据用户 ID 而非用户角色编辑仪表板

node.js - Postgres 不接受使用 docker-compose 的其他容器的任何连接

postgresql - docker nginx letsencrypt odoo错误

sql - 如何将数据库值连接成一个字符串?

php - wordpress元框混淆

mysql - 将 MySQL 查询结果以 CSV 文件导出到我的 PC

image - 如何将 youtube 嵌入代码中的 youtube 缩略图设置为 wordpress 中的特色图片?

node.js - npm package.json 和 docker(安装它...)