【发布时间】:2018-08-01 04:47:19
【问题描述】:
我希望 Docker 连接到我在本地运行的预先存在的 MySQL 数据库,而不是将 MySQL 数据库放在 Docker 或单独的卷中。
我使用的是 Laravel,因此是环境变量。
谁能帮忙?
这是我的 docker-compose.yml 文件:
version: '2'
services:
web:
image: nginx:latest
ports:
- "8080:80"
volumes:
- .:/code
- .docker/nginx.conf:/etc/nginx/conf.d/default.conf
php:
build:
context: .
dockerfile: .docker/Dockerfile
image: php:7-fpm
volumes:
- .:/code
environment:
DB_CONNECTION: mysql
DB_PORT: 3306
DB_HOST: mysql
DB_DATABASE: website_development
DB_USERNAME: website_username
DB_PASSWORD: website_pA$£w0r6
REDIS_HOST: redis
SESSION_DRIVER: redis
CACHE_DRIVER: redis
mysql:
image: mysql:5.7
ports:
- 13306:3306
environment:
MYSQL_DATABASE: website_development
MYSQL_USER: website_username
MYSQL_PASSWORD: website_pA$£w0r6
MYSQL_ROOT_PASSWORD: root_pA$£w0r6
redis:
image: redis:4.0-alpine
ports:
- 16379:6379
【问题讨论】:
-
Docker to connect to my pre-existing MySQL是什么意思? -
你不需要mysql服务。您不想启动 mysql 容器。我假设您在 3360 上使用正确的用户/密码/数据库等本地运行 MySQL。您只需要调整 DB_CONNECTION 值并指向您的本地 IP,如 192.168.xx.xx(不是本地主机!)。或者对于 mac,您可以使用:
docker.for.mac.localhost作为主机