2

I'm trying to run docker-compose.yml from here: https://github.com/Project-Books/book-project#running-the-app.

I tried to run a docker-compose file in Intellij IDEA Community Edition - using Docker plugin 202.7319.5

Here's the docker-compose.yaml file used: https://github.com/Project-Books/book-project/blob/master/docker-compose.yml

Here's the details about Docker Desktop installed:

OS: Windows
Version: 2.3.0.4(46911)
Channel: Stable
Engine: 19.03.12
Compose: 1.26.2

Output I'm getting in the console:

ERROR: for book-project_mysql_1  Cannot start service mysql: Ports are not available: listen tcp 0.0.0.0:3306: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
ERROR: for mysql  Cannot start service mysql: Ports are not available: listen tcp 0.0.0.0:3306: bind: Only one usage of each socket address (protocol/network address/port) is normally permitted.
Encountered errors while bringing up the project.
Dhannanjai
  • 302
  • 3
  • 13
  • Are you running MySQL (either in a container or outside Docker) on the host? That error message says "port 3306 on the host is already in use"; the thing that triggers it is port 3306 being the first port in a `ports:` setting. – David Maze Oct 11 '20 at 18:00

3 Answers3

5

The port 3306 is already in use by other application. You can deploy MySQL to another port.

example docker-compose:

version: '3'

services:
  mysql:
    image: mysql:latest
    hostname: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: bookproject
      MYSQL_USER: dbuser
      MYSQL_PASSWORD: dbpassword
    ports:
      - "3307:3306"
    volumes:
      - db_data:/var/lib/mysql
      - ./src/main/resources/db/init.sql:/data/application/init.sql
    command: --init-file /data/application/init.sql
  phpmyadmin:
    image: phpmyadmin/phpmyadmin:latest
    links:
      - mysql:db
    ports:
      - "8081:80"
  bookapp:
    build: ./
    restart: on-failure      
    ports: 
      - "8080:8080"
    environment:
      - WAIT_HOSTS=mysql:3307
      - WAIT_HOSTS_TIMEOUT=300
      - WAIT_SLEEP_INTERVAL=30
      - WAIT_HOST_CONNECT_TIMEOUT=30
      #- DEFAULT_PATH=<Target path in windows> 
    depends_on:
      - mysql
      - phpmyadmin
volumes:
  db_data:
n0nvme
  • 663
  • 1
  • 12
2

I solved the problem by ending the "mysqld.exe" process in the task manager. Because this process has occupied port 3306.

First i had to find out which programme was using the port. The windows integrated gui of the resource monitor helped me here.

This Post helped me

GJC
  • 21
  • 1
0

"Ports are not available: listen tcp 0.0.0.0:3306"

Port 3306 is already in use.

In docker-compose file:

ports:
  - "3306:3306"   # Map TCP port 3306 in the container to port 3306 on the Docker host.

Try to change mapping port on host to another port (ex: 3366):

version: '3'

services:
  mysql:
    image: mysql:latest
    hostname: mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
      MYSQL_DATABASE: bookproject
      MYSQL_USER: dbuser
      MYSQL_PASSWORD: dbpassword
    ports:
      - "3366:3306"
huytmb
  • 1,168
  • 1
  • 5
  • 12