I'm just trying to use Docker Swarm to manage multiple containers (similar to a load balancer) to allow for continuous deployments. My Dockerfile isn't the issue because I can run that perfectly fine and get the app on the specified port. However, I believe the issue lies in the docker-compose.yml file
Here's the docker-compose.yml file:
version: '3.7'
services:
nodejs:
image: username/image
env_file:
- .env
ports:
- "3000:3000"
deploy:
replicas: 4
update_config:
parallelism: 2
order: start-first
failure_action: rollback
delay: 10s
rollback_config:
parallelism: 0
order: stop-first
restart_policy:
condition: any
delay: 5s
max_attempts: 3
window: 120s
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000 || exit 1"]
Then after initiating docker swarm, I run docker stack deploy -c docker-compose.yml image --with-registry-auth
Running docker ps
shows
9a2188190f00 username/image:latest "docker-entrypoint.s…" 26 seconds ago Up 20 seconds (health: starting) 3000/tcp image_nodejs.1.ctwgtm2l2z0u1jykqgmch9nwx
102d4532160b username/image:latest "docker-entrypoint.s…" 26 seconds ago Up 20 seconds (health: starting) 3000/tcp image_nodejs.2.jj2ztzz8myz9x72lf88br4jal
1dc5966b21f1 username/image:latest "docker-entrypoint.s…" 26 seconds ago Up 20 seconds (health: starting) 3000/tcp image_nodejs.4.o53woh8bi1d0v91zdu06v4r5m
a89126214ee3 username/image:latest "docker-entrypoint.s…" 26 seconds ago Up 20 seconds (health: starting) 3000/tcp image_nodejs.3.wx7kl7vow1nphmetloo059ybg
Running docker service ls
shows
w5fm276y7b62 image_nodejs replicated 0/4 username/app:latest *:3000->3000/tcp
However, requests to localhost:3000 always show nothing running on that port. Any ideas? I've tried this solution, but it only spawns one container then.