How to Solve Error Message Error for Cannot start service : driver failed programming external connectivity on endpoint Bind for ipaddr:port failed: port is already allocated

Posted on

Introduction

In this article, the focus is just to show how to solve an error message. Basically, the error message itself exist below :

ERROR: for website_wordpress_1 Cannot start service wordpress: driver failed programming external connectivity on endpoint website_wordpress_1 (a29babac7159e0545dd041fd4ecdb7a059b81ea98fef2278231589298f989c55): Bind for 0.0.0.0:80 failed: port is already allocated

Before going on further to the solution, below is the execution of the command triggering the error message :

C:\repository\production\website>docker-compose up -d
Starting website_db_1 ... done
Starting website_phpmyadmin_1 ...
Starting website_wordpress_1 ...
Starting website_wordpress_1 ... error

ERROR: for website_wordpress_1 Cannot start service wordpress: driver failed programming external connectivity on endpoint 
Starting website-from-scratch_phpmyadmin_1 ... done
nd for 0.0.0.0:80 failed: port is already allocated

ERROR: for wordpress Cannot start service wordpress: driver failed programming external connectivity on endpoint website_wordpress_1 (a29babac7159e0545dd041fd4ecdb7a059b81ea98fef2278231589298f989c55): Bind for 0.0.0.0:80 failed: port is already allocated
ERROR: Encountered errors while bringing up the project.

C:\repository\production\website>

The above command execution is a ‘docker-compose’ command for pulling images, building it into container where services run. Before going on further, the following is the content of the file with the name ‘docker-compose.yml’ which very important as a requirement for the ‘docker-compose’ to run properly. As it appear in the above output command, there is an attempt from one of the service which is the ‘wordpress’

version: '3'
services:
  # Database
  db:
    image: mysql:5.7
    volumes:
      - "./mysql:/var/lib/mysql"
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: password
      MYSQL_DATABASE: wordpress
      MYSQL_USER: wordpress
      MYSQL_PASSWORD: wordpress
    networks:
      - wpsite
  # phpmyadmin
  phpmyadmin:
    depends_on:
      - db
    image: phpmyadmin/phpmyadmin
    restart: always
    ports:
      - '8080:80'
    environment:
      PMA_HOST: db
      MYSQL_ROOT_PASSWORD: password
    networks:
      - wpsite
  # WordPress
  wordpress:
    depends_on:
      - db
    image: wordpress:4.5.2
    ports:
      - '80:80'
    restart: always
    volumes:
      - "./html:/var/www/html"
      - "./apache2:/var/log/apache2"
    environment:
      WORDPRESS_DB_HOST: db:3306
      WORDPRESS_DB_USER: wordpress
      WORDPRESS_DB_PASSWORD: wordpress
    networks:
      - wpsite
networks:
  wpsite:
volumes:
  db_data:

How to Solve Error Message Bind for ipaddr:port failed: port is already allocated

The error message is actually occur because of the port for one of the service is not available. It is not available because it has been allocated to another resource. In order to check that port, one of the alternative is by listing the running Docker container. In this context, one of the running Docker container is using the port. The following is the execution for listing the running Docker container :

C:\repository\production\website>docker container list --all
CONTAINER ID IMAGE                     COMMAND                CREATED            STATUS             PORTS                     NAMES
09a8e1d78cf5 apps-using-source_www     "docker-php-entrypoi…" About an hour ago  Up About an hour   0.0.0.0:80->80/tcp     apps-from-scratch_www_1
9e9c8fe2aa51 phpmyadmin/phpmyadmin     "/docker-entrypoint.…" 9 hours ago        Up 58 minutes      0.0.0.0:8080->80/tcp   apps-from-scratch_phpmyadmin_1
4eaba84fc6c9 mysql:5.7                 "docker-entrypoint.s…" 9 hours ago        Up 58 minutes      3306/tcp, 33060/tcp    apps-from-scratch_db_1

C:\repository\production\website>

Unfortunately, that is the reason where the error message occur. Port 80 is not available for further usage as in the first line of the above output command execution. So, the solution is very simple. Actually, there are two kinds of solution in order to solve the problem. The solutions exist below :

  1. Just change the port in the ‘docker-compose.yml’ file, so that it will not use port ’80’.

  2. Another solution is just stop the other Docker container which is using the port. After that, run back the Docker container which exist as in the previous part for further execution.

In this case, the latter solution is the chosen one for solving the problem exist in this article. So, the following are steps for solving the problem :

  1. Stop the Docker container as follows :

    C:\repository\production\apps>docker-compose down
    Stopping apps-from-scratch_www_1 ... done
    Stopping apps-from-scratch_phpmyadmin_1 ... done
    Stopping apps-from-scratch_wordpress_1 ... done
    Stopping apps-from-scratch_db_1 ... done
    Removing apps-from-scratch_wordpress_1 ... done
    Removing apps-from-scratch_phpmyadmin_1 ... done
    Removing apps-from-scratch_wordpress_1 ... done
    Removing apps-from-scratch_db_1 ... done
    Removing network apps-from-scratch_wpsite
    
    C:\repository\production\apps>
    
  2. Next, run the previous Docker container once more as follows :
    C:\repository\production\website>docker-compose up -d
    Creating network "website" with the default driver
    Starting website_db_1 ... done
    Starting website_phpmyadmin_1 ...
    Starting website_wordpress_1 ...
    Creating website-using-source_db_1 ... done
    Creating website-using-source_www_1 ... done
    Creating website-using-source_phpmyadmin_1 ... done
    

 

Another solution which in this article it is the first solution is simply just change the port from the original ’80:80′ as in following one :

wordpress:
depends_on:
- db
image: wordpress:4.5.2
ports:
- '80:80'

Where the change in port ’80’ for an example will be in port ‘8000’ for instance. So, the docker-compose.yml for the ‘wordpress’ service after the change will be as follows :

wordpress:
depends_on:
- db
image: wordpress:4.5.2
ports:
- '8000:80'

Leave a Reply