Introduction
In this article, the focus is just to be able to solve an error message which appear. That error message appear as in the following line :
Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:3306 -> 0.0.0.0:0: listen tcp 0.0.0.0:3306: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted
Actually, the error message appear upon executing a specific command. That command is a ‘docker-compose’ where the execution of that command’s execution itself is in the command prompt. So, the following is the execution of that command triggering the error message :
C:\repository\production\website>docker-compose up -d [+] Running 3/4 - Network website-using-source_default Created 0.0s - Container website-using-source-db-1 Starting 0.4s - Container website-using-source-phpmyadmin-1 Created 0.2s - Container website-using-source-www-1 Created 0.2s Error response from daemon: Ports are not available: exposing port TCP 0.0.0.0:3306 -> 0.0.0.0:0: listen tcp 0.0.0.0:3306: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted. C:\repository\office\production\website>
The command above is a command for pulling Docker images, building it as Docker container and then run it. As in the above output, those processes unfortunately end in a failure. Because the necessary port which is port ‘3306’ is not available for further usage. In the Docker container, it is using port ‘3306’ for MySQL database service. The process above is using a file with the name of ‘docker-compose.yml’ which acts as a definition and description for the processes pulling images, creating Docker container and then use it for further execution. Before getting on to the solution, the following is the content of the script with the name of ‘docker-compose.yml’. It will be a reference for solving the problem. So, the context exist as follows :
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" environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress networks: - wpsite
How to Solve Error Message Error response from daemon: Ports are not available: exposing port TCP
So, the solution for solving the problem is in this part. There are two ways for solving the problem. Before going on into the details for the chosen way to solve the problem, the following is the list of option for solving the problems :
-
The first option, it is to change the port.
-
The second option, it is to disable the service which has already using that port.
In this example, the chosen solution for solving the problem is in the second option. So, disable the existing service using that port and use it for the Docker container. The following steps for solving the problem exist below :
-
First of all, just run the Command Prompt with a user which is possessing an Administrator privilege.
Microsoft Windows [Version 10.0.22000.795] (c) Microsoft Corporation. All rights reserved. C:\WINDOWS\system32>n
-
Next step, just type the following command to check listening port with the port number of ‘3306’ :
C:\WINDOWS\system32>netstat -aon | findstr :3306 TCP 0.0.0.0:3306 0.0.0.0:0 LISTENING 64328 TCP 0.0.0.0:33060 0.0.0.0:0 LISTENING 64328 TCP [::]:3306 [::]:0 LISTENING 64328 TCP [::]:33060 [::]:0 LISTENING 64328 C:\WINDOWS\system32>
So, port ‘3306’ is currently already listening with the process ID of ‘64328’.
-
For further step, just check the process with the ID of ‘64328’ where it is actually a service running by using port ‘3306’ for listening incoming request. But aside from that, just check the service list. Just search ‘service’ and then execute it. Normally, there is a general service running using port ‘3306’ which is MySQL service. So, search that service first in the service list as exist in the following image :
-
So, in order to solve the problem, just stop the MySQL server as in the following image :
After clicking the Stop menu, it will automatically will stop the MySQL service as in the following image :
-
If the process to stop MySQL service, it will change the status of the service from Running as follows :
-
After successfully stopping MySQL service, just continue on by starting the command once for running Docker container as follows :
C:\repository\production\website>docker-compose up -d Removing website-using-source_db_1 Recreating c18136cd1b92_website-using-source-db-1 ... done Recreating website-using-source-www-1 ... done Recreating website-using-source-phpmyadmin-1 ... done C:\>
Finally, the process is running without stop and it does not triggering any further error message. So, the solution for solving that problem is working.