Docker Compose
- Compose file version 3 reference | Docker Docs
- Deprecated Version Key Version and name top-level element | Docker Documentation
Use Node to bootstrap your app
NPM Scripts don’t pass OS signals
CMD ['node','server.js']
Docker Networks Port Binding to specific network interfaces
If we bind the port with 8080:8080
, we actually bind the port from address
0.0.0.0
. This means the container can also listen to our Wifi.
To restrict it more, we can tell docker to expose the port on the loopback
network interface with 127.0.0.1:8080:8080
.
Docker Volumes mounting file permissions
When mounting directories into containers, permissions can become a problem.
- file systems that don’t support Linux permissions natively (such as NTFS without the
permission
mount option) break containers relying on permission settings - If the container starts with a user different to the host, owner problems can
arise. Fix by specifying the Hosts UID/GID in the compose file:
user: "1000:1001"
. - Volume mounting breaks host/container isolation. Consider a different approach.
Docker Compose Healthchecks
services:
FoodPreparation:
image: node:latest
ports:
- 8084:3000
- 9229:9229
entrypoint: npm run
working_dir: /var/www/html
user: "1000:1001"
environment:
- AVAILABLE_COOKS=2
- DELIVERY_API=http://Delivery:5000
- FAILURE_ADD_LAZY_COOKS=${FAILURE_ADD_LAZY_COOKS}
- BUSY_COOK=${BUSY_COOK}
- RABBITMQ_HOST=rabbitmq
- RABBITMQ_PROTOCOL=${RABBITMQ_PROTOCOL}
- RABBITMQ_DEFAULT_USER=${RABBITMQ_USER}
- RABBITMQ_DEFAULT_PASS=${RABBITMQ_PASSWORD}
- RABBITMQ_DEFAULT_VHOST=${RABBITMQ_VHOST}
volumes:
- ./food-preparation:/var/www/html:rw
networks:
- restaurant-kata
healthcheck:
test: ["CMD", "curl", "--fail", "http://localhost:${FOOD_PREPARATION_PORT}/api/health"]
interval: 30s # optional
timeout: 5s # optional
retries: 3 # optional
start_period: 10s # optional
depends_on:
redis:
condition: service_healthy