【发布时间】:2017-02-17 13:36:19
【问题描述】:
我想在一个桥接网络下将三个服务(db、nginx 和 web 服务)链接在一起,并且能够从我的本地主机或容器内部戳不同的服务,并有一个用于 web 的交互式终端服务。我怎样才能做到这一点?
我的 docker-compose 配置如下:
version: '2'
services:
web:
build:
context: .
dockerfile: Dockerfile-alpine
command: /bin/bash
ports:
- "5000:5000"
volumes:
- $REPO_DIR:/repository
links:
- db
- nginx
nginx:
image: nginx:stable-alpine
ports:
- "8080:8080"
volumes:
- $NGINX_STATIC_DIR:/var/www/static
- $NGINX_CONFIG_FILE:/etc/nginx/nginx.conf
db:
image: mysql/mysql-server
ports:
- "3307:3306"
environment:
MYSQL_USER: $MYSQL_USER
MYSQL_PASSWORD: $MYSQL_PASSWORD
MYSQL_DATABASE: $MYSQL_DATABASE
MYSQL_ROOT_PASSWORD: $MYSQL_ROOT_PASSWORD
volumes:
- $DB_DATA_DIR:/var/lib/mysql
- $DB_LOG_DIR:/var/log/mysql
Web 服务使用 mhart/alpine-node:6.7.0 作为基础,并进一步添加了一些实用程序以及 Python3.5 和 Flask。
如果我执行docker-compose run web,我可以访问交互式终端,但 db 和 nginx 服务未正确启动/链接。我得到以下输出:
Starting courseadmin_nginx_1
Starting courseadmin_db_1
bash-4.3#
然后从容器内部进行进一步的网络取证,发现 nginx 或 db 都不存在。我可以进一步支持这一说法,因为使用 docker-compose up 实际上会为我在主机系统上安装 mysql 的 db 服务创建端口冲突,而 docker-compose run 从未报告过。
另一方面,如果我尝试docker-compose up,我会得到更活跃的跟踪,但没有交互式终端:
Starting courseadmin_nginx_1
Recreating courseadmin_db_1
Recreating courseadmin_web_1
Attaching to courseadmin_nginx_1, courseadmin_db_1, courseadmin_web_1
db_1 | Initializing database
courseadmin_web_1 exited with code 0
db_1 | Database initialized
db_1 | MySQL init process in progress...
db_1 | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
db_1 | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
db_1 | mysql: [Warning] Using a password on the command line interface can be insecure.
db_1 | mysql: [Warning] Using a password on the command line interface can be insecure.
db_1 | mysql: [Warning] Using a password on the command line interface can be insecure.
db_1 | mysql: [Warning] Using a password on the command line interface can be insecure.
db_1 |
db_1 | /entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*
db_1 |
db_1 |
db_1 | MySQL init process done. Ready for start up.
db_1 |
如何实现交互式终端和正确链接我的三个容器?
【问题讨论】:
标签: networking docker docker-compose environment docker-container