I would like to link three services together (db, nginx, and web service) under a bridge network and be able to poke at the different services from my localhost or from inside the container, and have an interactive terminal for the web service. How can I achieve this?
My docker-compose configuration is the following:
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
where the web service is using the mhart/alpine-node:6.7.0
as a base and further adds some utilities plus Python3.5 and Flask.
If I do docker-compose run web
, I get access to an interactive terminal, but the db and nginx services are not booted/linked properly. I get the following output:
Starting courseadmin_nginx_1
Starting courseadmin_db_1
bash-4.3#
And then further network forensics from inside the container turns up that neither nginx or db are present. I can further support this claim since using docker-compose up
actually created a port conflict for the db service granted that I have mysql installed on my host system, thing it never reported with docker-compose run
.
On the other hand, if I try docker-compose up
, I get a much more active trace, but no interactive terminal:
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 |
What can I do to achieve an interactive terminal and proper linking of my three containers?