I am running an experiment locally and I want to start one service that listen to a few ports, communicates with redis, and is externally accessible
version: "3.3"
services:
redis:
image: redis
networks:
- office
ports:
- '6379:6379'
workers:
image: workers-image
networks:
- office
environment:
NUM_WORKERS: 10
REDIS_URI: 'redis://redis:6379'
ports:
- '15658-15680:15658-15680'
depends_on:
- redis
I was expecting to be able to access the workers
service using eg 127.0.0.1:15660
, or, preferrably, something like workers.office:15660
.
Can someone point me out what I am doing wrong?
Sorry if after reading the original post it was not clear that what is not working as expected
After I start the workers
service
docker-compose run -e NUM_WORKERS=10 workers
It will listen to a few different ports. Then I was expecting to be able to be able to get a response with
> curl 127.0.0.1:15660/metrics
curl: (7) Failed to connect to 127.0.0.1 port 15658: Connection refused
or
> curl workers.host:15658/metrics
curl: (6) Could not resolve host: workers.host
Docker run
won't expose ports unless you pass --service-ports
to the command, eg docker-compose run --service-ports -e NUM_WORKERS=10 workers
.
Also, the service-ports are created while building the container, so if you change the docker-compose file you have to run docker compose build
again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.