Description
I am trying to run a few FastAPI instances with the same route. The main file to start the server chooses a random port from 8000 to 8010.
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=random.randrange(8000, 8010))
My docker-compose yml file looks like this:
version: '3.9'
services:
api:
build: .
ports:
- "8080-8010:8080-8010"
Steps to reproduce the issue:
- Create a simple FastAPI server with one route and a starter file that runs the app with uvicorn and chooses a random port
- Use the provided compose file
Describe the results you received:
Command I used to start Docker Compose:
docker compose up --scale=5
[+] Running 2/0
⠿ Container some-api-2 Recreated 0.1s
⠿ Container some-api-1 Recreated 0.1s
Attaching to some-api-1, ytstars-api-2
Error response from daemon: driver failed programming external connectivity on endpoint some-api-2: Bind for 0.0.0.0:8010 failed: port is already allocated
Describe the results you expected:
Additional information you deem important (e.g. issue happens only occasionally):
Output of docker compose version:
Docker Compose version v2.6.0
Output of docker info:
Client:
Context: default
Debug Mode: false
Plugins:
app: Docker App (Docker Inc., v0.9.1-beta3)
buildx: Docker Buildx (Docker Inc., v0.8.2-docker)
compose: Docker Compose (Docker Inc., v2.6.0)
scan: Docker Scan (Docker Inc., v0.17.0)
Server:
Containers: 2
Running: 1
Paused: 0
Stopped: 1
Images: 11
Server Version: 20.10.17
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: cgroupfs
Cgroup Version: 1
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: io.containerd.runc.v2 io.containerd.runtime.v1.linux runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 10c12954828e7c7c9b6e0ea9b0c02b01407d3ae1
runc version: v1.1.2-0-ga916309
init version: de40ad0
Security Options:
seccomp
Profile: default
Kernel Version: 5.10.16.3-microsoft-standard-WSL2
Operating System: Ubuntu 20.04.4 LTS
OSType: linux
Architecture: x86_64
CPUs: 4
Total Memory: 15.54GiB
Name: vortex
ID: VE5W:P4DU:3P32:RM4L:FZVW:MGBB:LTVY:DY6N:TYLL:QF2W:5W5N:BTRS
Docker Root Dir: /var/lib/docker
Debug Mode: false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false
WARNING: No blkio throttle.read_bps_device support
WARNING: No blkio throttle.write_bps_device support
WARNING: No blkio throttle.read_iops_device support
WARNING: No blkio throttle.write_iops_device support
Additional environment details:
Description
I am trying to run a few FastAPI instances with the same route. The main file to start the server chooses a random port from 8000 to 8010.
My docker-compose yml file looks like this:
Steps to reproduce the issue:
Describe the results you received:
Command I used to start Docker Compose:
Describe the results you expected:
Additional information you deem important (e.g. issue happens only occasionally):
Output of
docker compose version:Output of
docker info:Additional environment details: