Josh Kaiser
Josh Kaiser

Reputation: 116

Docker Error bind: address already in use when port is not in use

I'm running docker-compose up for the following docker-compose.yml file:

version: '3.7'
services:
  mysql_db_container:
    image: mysql:latest
    command: --default-authentication-plugin=mysql_native_password
    environment:
      MYSQL_ROOT_PASSWORD: rootpassword
    ports:
      - "3306:3306"
    volumes:
      - mysql_db_data_container:/var/lib/mysql
  adminer_container:
    image: adminer:latest
    environment:
      ADMINER_DEFAULT_SERVER: mysql_db_container
    ports:
      - "8080:8080"

volumes:
  mysql_db_data_container:

and I'm getting the following error:

ERROR: for mysql_db_container  Cannot start service mysql_db_container: Ports are not available: listen tcp 0.0.0.0:3306: bind: address already in use
ERROR: Encountered errors while bringing up the project.

I've tried the follow:

docker-compose stop && docker-compose down

then

docker ps -a

results in:

CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES

I ran:

netstat | grep :3306

it returned nothing.

I'm thinking the issue may be with the docker-compose file, but I'm not sure. Any ideas on how to free the port so the container can run are much appreciated.

Upvotes: 2

Views: 4629

Answers (1)

Josh Kaiser
Josh Kaiser

Reputation: 116

The cause: MySQL was already running on the computer.

The solution: On mac: System Preferences > MySQL > Stop MySQL Server

Upvotes: 8

Related Questions