docker-compose.yml
version: '2'
services:
api:
build: .
links:
- mongo:mongo
ports:
- 9527:9527
restart: unless-stopped
volumes:
- $PWD:/usr/src/app/
env_file:
- .env
environment:
- MONGO_HOST=mongodb://mongo/api
hostname: api
depends_on:
- mongo
mongo:
image: bitnami/mongodb:latest
hostname: mongo
restart: unless-stopped
ports:
- 27017:27017
Api container’s/etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.18.0.3 api
Mongo container/etc/hosts
127.0.0.1 localhost
::1 localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
172.18.0.2 mongo
There is no problem in creating, but according to my understanding, it should be inapi
Container/etc/hosts
Create an alias, the result is no, just created the container’s own
It has been solved and it is good to use it directly.