Docker-compose up failing because "port is already allocated"
Problem
My docker container is able to successfully build but when I enter the command docker-compose build, the following error is returned: Starting docker_etl_1 ... Starting 1e5f56853e10_1e5f56853e10_1e5f56853e10_docker_postgis_1 ... Starting 1e5f56853e10_1e5f56853e10_1e5f56853e10_docker_postgis_1 Starting 1e5f56853e10_1e5f56853e10_1e5f56853e10_docker_postgis_1 ... error ERROR: for 1e5f56853e10_1e5f56853e10_1e5f56853e10_docker_postgis_1 Cannot start service postgis: driver failed programming external connectivity on endpoint 1e5f56853e10_1e5f56853e10_1e5f56853e10_docker_postgis_1 (91464afbee8bf7212061797ec0f4c017a56cc3c30c9bdaf513127a6e6a4a5a52): Error starting userland prStarting docker_etl_1 ... done ERROR: for postgis Cannot start service postgis: driver failed programming external connectivity on endpoint 1e5f56853e10_1e5f56853e10_1e5f56853e10_docker_postgis_1 (91464afbee8bf7212061797ec0f4c017a56cc3c30c9bdaf513127a6e6a4a5a52): Error starting userland proxy: Bind for 0.0.0.0:5432 failed: port is already allocated Here is my docker-compose.yaml version: '2' services: postgis: build: ./postgis volumes: - ../src/main/sql:/sql ports: - "5432:5432" etl: build: ./etl volumes: - ..:/national-voter-file entrypoint: - python3 - /national-voter-file/load/loader.py and here is the Dockerfile: FROM m
Error Output
error
ERROR: for 1e5f56853e10_1e5f56853e10_1e5f56853e10_docker_postgis_1 Cannot start service
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Resolve Port Allocation Conflict for Docker PostGIS Service
The error occurs because the port 5432 is already in use by another process on the host machine. This prevents Docker from binding the PostGIS service to the specified port, leading to the failure in starting the container.
Awaiting Verification
Be the first to verify this fix
- 1
Identify the Process Using Port 5432
Use the command line to find out which process is currently using port 5432. This will help you determine if it's another Docker container or a different application.
bashlsof -i :5432 - 2
Stop the Conflicting Process
Once you identify the process using port 5432, you can stop it. If it's another Docker container, you can stop it using Docker commands. If it's another application, use the appropriate command to terminate it.
bashdocker stop <container_id> # Replace <container_id> with the actual ID - 3
Change PostGIS Port Mapping (Optional)
If you cannot stop the process using port 5432, consider changing the port mapping for the PostGIS service in your docker-compose.yaml file to an available port, such as 5433.
yamlports: - "5433:5432" - 4
Restart Docker Compose
After resolving the port conflict, restart your Docker Compose setup to apply the changes and start the services.
bashdocker-compose up
Validation
Check the output of 'docker-compose up' to ensure that the PostGIS service starts without errors. Additionally, verify that you can connect to the PostGIS service using the specified port.
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep