Home > OS >  How to get around network mapping issue "Bind for 0.0.0.0:8080 failed: port is already allocate
How to get around network mapping issue "Bind for 0.0.0.0:8080 failed: port is already allocate

Time:11-09

I'm trying to build a Jenkins docker container by following this page so I can test locally. Problem is with this is that once I've ran docker run -it -p 8080:8080 jenkins/jenkins:lts it seems I cannot use the same port for my docker-compose.yml:

version: '3.8'
services:
  jenkins:
    image: jenkins/jenkins:lts
    container_name: jenkins
    user: root
    privileged: true
    ports:
      - 8080:8080
      - 50000:50000
    volumes:
        - .jenkins/jenkins_configuration:/var/jenkins_home
        - /var/run/docker.sock:/var/run/docker.sock

The error shown in PowerShell (I'm on windows 10 if that's relevant) is:

Error response from daemon: driver failed programming external connectivity on endpoint jenkins (xxxx): Bind for 0.0.0.0:8080 failed: port is already allocated

I've made sure it's not affected from another container, image or volume and have deleted everything apart from this.

I wish to use Jenkins locally but how can I get around this? I'm not familiar with networking and what I've googled so far has not seemed to work for me. I would like this to be able to use Jenkins ui on localhost:8080

CodePudding user response:

If port 8080 is already allocated on your host machine, you can just map a different one to 8080 of the container instead. Two things can't be mapped to the same port on the host machine. In order to map 8081 for example, change your compose to the following:

version: '3.8'
services:
  jenkins:
    image: jenkins/jenkins:lts
    container_name: jenkins
    user: root
    privileged: true
    ports:
      - 8081:8080 # a different port is mapped here
      - 50000:50000
    volumes:
        - .jenkins/jenkins_configuration:/var/jenkins_home
        - /var/run/docker.sock:/var/run/docker.sock

Then, you just need to access the container started by docker-compose with port localhost:8081 rather than localhost:8080.

  • Related