我試圖讓一個web服務器容器連接一個mysql服務器容器,但當我嘗試在mysql服務器上連接時,我收到了未知的主機,如phpmyadmin。如何將docker容器鏈接到外部mysql容器?
這裏我的MySQL泊塢窗,compose.yml
version: '3'
services:
mysqldb:
image: mysql
container_name: mysql
restart: always
env_file:
- ".env"
environment:
- MYSQL_DATABASE=${MYSQL_DATABASE}
- MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
- MYSQL_USER=${MYSQL_USER}
- MYSQL_PASSWORD=${MYSQL_PASSWORD}
ports:
- "3306:3306"
expose:
- "3306"
volumes:
- "./data/mysql:/var/lib/mysql"
在這裏,我的Web服務器容器
version: '3'
services:
web:
image: nginx:latest
container_name: web
ports:
- "80:80"
- "443:443"
restart: always
volumes:
- "./etc/nginx/nginx.conf:/etc/nginx/nginx.conf"
- "./etc/nginx/sites-enabled:/etc/nginx/sites-enabled"
- "./etc/nginx/default.conf:/etc/nginx/conf.d/default.conf"
- "./etc/ssl:/etc/ssl"
- "./web:/var/www/html"
- "./data/domains:/domains"
depends_on:
- php
external_links:
- "mysql:mysql"
php:
image: nanoninja/php-fpm
restart: always
volumes:
- "./etc/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
- "./web:/var/www/html"
- "./data/domains:/domains"
myadmin:
image: phpmyadmin/phpmyadmin
container_name: phpmyadmin
ports:
- "8080:80"
environment:
- PMA_ARBITRARY=1
- PMA_HOST=mysql
restart: always
external_links:
- "mysql:mysql"
難道我設置泊塢窗,撰寫文件是否正確?
編輯1:
[email protected]:~/docker# docker ps | grep mysql
0d49167a6aae mysql "docker-entrypoint..." About an hour ago Up About an hour 0.0.0.0:3306->3306/tcp mysql
謝謝你,我沒有意識到這個名字需要相同,因爲我使用了container_name選項。我會嘗試這些改變; –
這是我的錯,我沒有看到你使用'container_name'。給我幾分鐘 –
更正了我的答案 –