Slide 12
Slide 12 text
BEHIND THE SCENES
services:
web:
build:
context: ./basic-react-project
ports:
- 8080:3000
depends_on:
- mongo
- api
api:
build:
context: ./MyNodeJsProject
ports:
- 8081:5000
depends_on:
- mongo
healthcheck:
mongo:
image: mongo:3.6.3
ports:
- "27017"
volumes:
- api-mongo-db:/data/db
When you run docker-compose up, the following happens:
1.A network named storeapp_default is created by default
2.A container named storeapp_web_1 is created
3.A container named storeapp_api_1 is created
4.A container named storeapp_mongo_1 is created
5.All the services joins the network storeapp_default
➤App is named after the directory it lives in but can be overridden by the -p flag
➤The default network is named _default i.e.
storeapp_default
➤Each container for a service joins the default network,
➤and is both reachable by other containers on that network,
➤and discoverable by them at a hostname identical to the container name.
➤Networked service-to-service communication use the CONTAINER_PORT.
➤When HOST_PORT is defined, the service is accessible outside the swarm as
well.
➤Within the storeapp_web_1 container, your connection string to Mongo
database would look like mongodb://mongo:27017/
docker-compose -p storeapp up