我正在尝试将现有项目移动到Docker。我在M.Academy上遵循了本教程,并在现有项目上遵循了Docker的设置说明
当执行尝试连接MySQL时,我收到此错误ERROR 2002(HY 000):无法连接到“db”上的MySQL服务器(115)
我还试图执行:telnet db 3306
响应:正在尝试172.17.0.1...远程登录:无法连接到远程主机:联机逾时
我尝试了所有的方法,但还是不能解决问题。我是Docker的新手。我使用的是Ubuntu 18.04 LTE。在导入数据库之前,没有更改db.env,并且在其他任何步骤上都没有错误。
我进一步检查,发现容器无法与MySQL建立连接。
P.S.我能够通过使用(外部MySQL端口)mysql -h 127.0.01 -u root -p -P 3306
成功连接Docker容器外部的相同MySQL服务
重现步骤
1.在Ubuntu 18.04上安装Docker和Docker Compose
1.下载Docker合成模板:curl -s https://raw.githubusercontent.com/markshust/docker-magento/master/lib/template | bash
1.替换为现有Magento示例的现有源代码:cp -R ~/Sites/existing src
1.执行:docker-compose -f docker-compose.yml up -d
1.将文件复制到容器:bin/copytocontainer --all
1.导入现有数据库:bin/mysql < /var/www/magento243.sql
预期结果数据库应已成功导入
实际结果错误2002(HY 000):无法连接到'db'上的MySQL服务器(115)
P.S.问题已在此处提出:https://github.com/markshust/docker-magento/issues/589
停靠-撰写.yml
version: "3"
services:
app:
image: markoshust/magento-nginx:1.18-5
ports:
- "80:8000"
- "443:8443"
depends_on:
- "db"
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.4-fpm-11
volumes: *appvolumes
extra_hosts: *appextrahosts
env_file: env/phpfpm.env
db:
image: mariadb:10.4
command: --max_allowed_packet=256M
ports:
- "3306:3306"
env_file: env/db.env
volumes:
- dbdata:/var/lib/mysql
extra_hosts: *appextrahosts
redis:
image: redis:5.0-alpine
ports:
- "6379:6379"
extra_hosts: *appextrahosts
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"
extra_hosts: *appextrahosts
rabbitmq:
image: rabbitmq:3.8.22-management-alpine
ports:
- "15672:15672"
- "5672:5672"
volumes:
- rabbitmqdata:/var/lib/rabbitmq
environment:
- RABBITMQ_VM_MEMORY_HIGH_WATERMARK=1GB
extra_hosts: *appextrahosts
mailcatcher:
image: sj26/mailcatcher
ports:
- "1080:1080"
extra_hosts: *appextrahosts
## 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:
1条答案
按热度按时间pvcm50d11#
此问题最终由以下人员解决
1.正在从YML文件中删除***extra_hosts*条目
1.在YML中添加*网络***
最终版本停靠-撰写.yml