Docker Compose:
If we are running application with multiple service, better way to use docker compose. docker compose is accompolished with configuration with YAML files docker-compose.yml files holds different services and its options to run the services. once docker-compose.yml is ready docker-compose up simple command will bring all the mentioned service up.
Link the Container:
Each services are independent and it is necessary to link the services to have better communciation. docker run -d –name =vote -p 5000:80 –link redis:redis voting-app It creates entry in voting app container /etc/hosts redis and internal ip of redis ccontainer.
–link will deprecating with advanced configuration. docker-compose gives good control over links and network config.
docker-compose version: 1
redis:
image: redis
db:
image: postgres:9.4
vote:
image ./vote
port:
- 5000:80
links:
- redis
result:
image: result
ports:
- 5001:80
Links:
- db
worker:
image: worker
links:
- db
- redis###Docker compose version 2 links will be automatically made.
version: 2
services:
redis:
image: redis
networks:
-back-end
db:
image: postgres:9.4
networks:
-back-end
vote:
image ./vote
port:
- 5000:80
networks:
-front-end
-back-end:
result:
image: result
ports:
- 5001:80
networks:
-front-end
-back-end
worker:
image: worker
networks:
front-end:
back-end: