我想在桥接网络下将三个服务(db,nginx和web服务)链接在一起,并能够从我的本地主机或容器内戳出不同的服务,并且拥有一个Web服务的交互式终端。我怎样才能做到这一点?Docker撰写链接的终端
我搬运工-撰写配置如下:
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和烧瓶中。
如果我做docker-compose run web
,我可以访问一个交互式终端,但db和nginx服务没有正确启动/链接。我得到以下输出:
Starting courseadmin_nginx_1
Starting courseadmin_db_1
bash-4.3#
然后从容器内部进一步的网络取证发现,既不存在nginx也不存在db。我可以进一步支持这种说法,因为使用docker-compose up
实际上为db服务创建了一个端口冲突,因为我在主机系统上安装了mysql,它从未报告过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 |
我能做些什么来实现我的三个容器的交互终端和适当的链接?
的'泊坞窗,compose'文档我一直在谈论可以在这里找到,特别是约'links'部分:https://docs.docker.com/compose/networking/#/links – d00bsm3n
好帖子!这对我的进步无疑很有帮助。但是我不能这样做docker exec -ti $ container_id,因为我的web容器一直在死,因为/ bin/bash没有任何事情要做。有没有什么办法可以让我活着而不需要通过任何入口点? –
为防万一你不清楚**为什么**你的'web'容器死了,请看[这里](http://stackoverflow.com/a/28214133/6942595)。对于其他人,你能否在你的OP中详细说明你想通过你的web服务获得什么?对我来说,你似乎可以简单地做'image:alpine',它会建立一个容器,然后你可以用'exec'启动一个shell? – d00bsm3n