【问题标题】:Docker ERROR 2002 (HY000): Can't connect to MySQL server on 'db' (115)Docker 错误 2002 (HY000): 无法连接到“db”上的 MySQL 服务器 (115)
【发布时间】:2021-12-29 05:18:35
【问题描述】:

我使用带有 https://github.com/markshust/docker-magento 的 docker。当我一步一步尝试导入数据库时​​,出现错误 ERROR 2002 (HY000): Can't connect to MySQL server on 'db' (115) 我试过这个解决方案ERROR 2002 (HY000): Can't connect to MySQL server on 'db' (115)。 我的 yml 文件

    ## Mark Shust's Docker Configuration for Magento
## (https://github.com/markshust/docker-magento)
##
## Version 41.0.2

## To use SSH, see https://github.com/markshust/docker-magento#ssh
## Linux users, see https://github.com/markshust/docker-magento#linux

## If you changed the default Docker network, you may need to replace
## 172.17.0.1 in this file with the result of:
## docker network inspect bridge --format='{{(index .IPAM.Config 0).Gateway}}'

version: "3"

services:
  app:
    image: markoshust/magento-nginx:1.18-5
    ports:
      - "80:8000"
      - "443:8443"
    volumes: &appvolumes
      - ~/.composer:/var/www/.composer:cached
      - ~/.ssh/id_rsa:/var/www/.ssh/id_rsa:cached
      - ~/.ssh/known_hosts:/var/www/.ssh/known_hosts:cached
      - appdata:/var/www/html
      - sockdata:/sock
      - ssldata:/etc/nginx/certs
    extra_hosts: &appextrahosts
      ## M1 Mac support to fix Docker delay, see #566
      - "app:172.17.0.1"
      - "phpfpm:172.17.0.1"
      - "db:172.17.0.1"
      - "redis:172.17.0.1"
      - "elasticsearch:172.17.0.1"
      - "rabbitmq:172.17.0.1"
      ## Selenium support, replace "magento.test" with URL of your site
      - "magento.test:172.17.0.1"

  phpfpm:
    image: markoshust/magento-php:7.2-fpm
    volumes: *appvolumes
    env_file: env/phpfpm.env
      
  db:
    image: mariadb:10.1
    command: mysqld --innodb_force_recovery=6 --lower_case_table_names=1 --skip-ssl --character_set_server=utf8mb4 --explicit_defaults_for_timestamp
    ports:
      - "3306:3306"
    env_file: env/db.env
    volumes:
      - dbdata:/var/lib/mysql



  redis:
    image: redis:6.0-alpine
    ports:
      - "6379:6379"

  elasticsearch:
    image: markoshust/magento-elasticsearch:7.9.3-1
    ports:
      - "9200:9200"
      - "9300:9300"
    environment:
      - "discovery.type=single-node"
      ## Set custom heap size to avoid memory errors
      - "ES_JAVA_OPTS=-Xms1g -Xmx1g"
      ## Avoid test failures due to small disks
      ## More info at https://github.com/markshust/docker-magento/issues/488
      - "cluster.routing.allocation.disk.threshold_enabled=false"
      - "index.blocks.read_only_allow_delete"

  rabbitmq:
    image: rabbitmq:3.8.22-management-alpine
    ports:
      - "15672:15672"
      - "5672:5672"
    volumes:
      - rabbitmqdata:/var/lib/rabbitmq
    env_file: env/rabbitmq.env

  mailcatcher:
    image: sj26/mailcatcher
    ports:
      - "1080:1080"

  ## Selenium support, uncomment to enable
  #selenium:
  #  image: selenium/standalone-chrome-debug:3.8.1
  #  ports:
  #    - "5900:5900"
  #  extra_hosts: *appextrahosts

volumes:
  appdata:
  dbdata:
  rabbitmqdata:
  sockdata:
  ssldata:

【问题讨论】:

  • 所有这些额外的主机和端口映射看起来都很可疑。为什么不只依靠撰写自动名称映射?
  • 您能否尝试运行docker log container-id 来检查问题,然后在此处引用?
  • 另外,让我们检查一下文件 app/etc/env.php 是否存在

标签: docker magento


【解决方案1】:

请记住,您需要连接到正在运行的 docker 容器。所以你可能想使用 TCP 而不是 Unix 套接字。检查 docker ps 命令的输出并查找正在运行的 MySQL 容器。如果你找到了,那么使用 MySQL 命令: MySQL -h 127.0.0.1 -P (你会在 docker ps 输出中找到一个端口)。如果在 docker ps 输出中找不到任何正在运行的 MySQL 容器,请尝试使用 docker images 来查找 MySQL 映像名称并尝试使用以下方法运行它: docker run -d -p 3306:3306 tutum/MySQL where "tutum/MySQL"是在 docker 图像中找到的图像名称。

【讨论】:

    猜你喜欢
    • 2022-01-15
    • 2018-10-29
    • 2021-01-16
    • 1970-01-01
    • 1970-01-01
    • 2013-03-05
    • 2019-01-26
    • 2014-11-27
    相关资源
    最近更新 更多