You're missing the HOST_PORT
part in your server
service definition. A service's port definition should be HOST_PORT:CONTAINER_PORT
as per https://docs.docker.com/compose/networking/. Otherwise a random HOST_PORT
will be chosen.
You can clone a working sample environment here or see it working here.
You can always see which port Docker Compose is choosing by issuing:
jdsalaro$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
de0120c61c1e 65896179-get-exposed-port-from-within-docker-compose_server "/bin/sh -c 'uwsgi -…" 12 seconds ago Up 11 seconds 0.0.0.0:49157->8086/tcp 65896179-get-exposed-port-from-within-docker-compose_server_1
To fix your problem, just provide a HOST_PORT
as mentioned:
version: "3.9"
services:
server:
build: .
ports:
- "8086:8086"
environment:
- PORT=8086
When using --scale
, for example --scale server=4
, one can provide a range of ports as HOST_PORT
instead as follows:
version: "3.9"
services:
server:
build: .
ports:
- "8000-8004:8086"
environment:
- PORT=8086
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…