Introduction
Another article where the main focus is discussing about how to solve an error message occur. The error message itself appear upon executing the ‘docker-compose’ command. Specifically, the error appear on the ‘docker-compose’ command execution with additional parameter of ‘build’. The following is the actual command execution along with the output where it contain the error message :
C:\repository\docker\website>docker-compose up -d [+] Running 2/3 - Container website-db-1 Running 0.0s - Container website-phpmyadmin-1 Started 3.9s - Container website-wordpress-1 Starting 2.4s Error response from daemon: driver failed programming external connectivity on endpoint website-wordpress-1 (61f301558dcb7cdd022c6c6fb53343508cc68573dd7c507416a1dec9af858403): Bind for 0.0.0.0:8000 failed: port is already allocated C:\repository\docker\website>
As it exist in the above output of the ‘docker-compose build’ command execution, there is a specific error message exist. That specific error message exist below :
Error response from daemon: driver failed programming external connectivity on endpoint website-wordpress-1 (61f301558dcb7cdd022c6c6fb53343508cc68573dd7c507416a1dec9af858403): Bind for 0.0.0.0:8000 failed: port is already allocate
Before going on further, the following is the actual content of the docker-compose.yml file :
version: '3.3' services: db: image: mysql:5.7 volumes: - "./mysql:/var/lib/mysql:rw" restart: always environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress phpmyadmin: depends_on: - db image: phpmyadmin/phpmyadmin restart: always ports: - '8000:80' environment: PMA_HOST: db MYSQL_ROOT_PASSWORD: somewordpress wordpress: depends_on: - db image: wordpress:latest ports: - '8000:80' restart: always volumes: - "./website:/var/www/html:rw" environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress
How to Solve Error Message Bind for port number failed: port is already allocated
It is an obvious error message with an obvious solution. As it exist in the previous part, one of the service building process end in a failure. The reason is because the port has already allocated. In the script ‘docker-compose.yml’ above, all the services have their own ports. The ‘db’ service with the port of ‘3306’. The second one, the ‘phpmyadmin’ service with the port of ‘8000’. And the last service, it is the service with the name of ‘wordpress’ where it has the port of ‘8000’. So, there are two services with the same port. It can create a conflict between the two of them. In other words, the ‘phpmyadmin’ service is already running using port ‘8000’. If there is another process for building another service after with the same port, it will trigger that kind of error message. In this example, the solution is by changing one of the service’s port. Just change one of them where in this example, just change the ‘phpmyadmin’ port from ‘8000’ to ‘7000’. After editing or revising the ‘docker-compose.yml’ file, the content will be in the following appearance :
version: '3.3' services: db: image: mysql:5.7 volumes: - "./mysql:/var/lib/mysql:rw" restart: always environment: MYSQL_ROOT_PASSWORD: somewordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress phpmyadmin: depends_on: - db image: phpmyadmin/phpmyadmin restart: always ports: - '7000:80' environment: PMA_HOST: db MYSQL_ROOT_PASSWORD: somewordpress wordpress: depends_on: - db image: wordpress:latest ports: - '8000:80' restart: always volumes: - "./website:/var/www/html:rw" environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress
Soon after, execute the command once more. The following is the execution of that command :
C:\repository\docker\website>docker-compose up -d [+] Running 3/3 - Container website-db-1 Started 0.2s - Container website-phpmyadmin-1 Started 0.7s - Container website-wordpress-1 Started 0.7s C:\repository\docker\website>
It is fortunate that after changing one of the services’s port, the command execution is a success. Furthermore, it also does not generate further error message.