Search code examples
laraveldockerlaradock

Docker killing 3306 usage port cause of crashing docker


I'm using MaxOs and after install Docker i tried to install LaraDock,running this command which that was into LaraDoc documentation:

laradock % docker-compose up -d nginx mariadb phpmyadmin redis workspace

return this error:

laradock_mariadb_1 is up-to-date
laradock_docker-in-docker_1 is up-to-date
laradock_redis_1 is up-to-date
Starting laradock_mysql_1 ...
Starting laradock_mysql_1     ... error
WARNING: Host is already in use by another container

ERROR: for laradock_mysql_1  Cannot start service mysql: driver failed programming external 

connectivity on endpoint laradock_mysql_1 (a75f179cd36ac95540f346d1c75ff105904cc8717690152ac90b92383c847a3b): Bind for 0.0.0.0:3306 failed: port is already allocated
    Starting laradock_workspace_1 ... error
    
    ERROR: for laradock_workspace_1  Cannot start service workspace: driver failed programming external connectivity on endpoint laradock_workspace_1 (fd6a03d680c668acae7f6db40ad7f5d9951a267cdf7e7686f66f751f91cece17): Bind for 0.0.0.0:8080 failed: port is already allocated
    
    ERROR: for mysql  Cannot start service mysql: driver failed programming external connectivity on endpoint laradock_mysql_1 (a75f179cd36ac95540f346d1c75ff105904cc8717690152ac90b92383c847a3b): Bind for 0.0.0.0:3306 failed: port is already allocated
    
    ERROR: for workspace  Cannot start service workspace: driver failed programming external connectivity on endpoint laradock_workspace_1 (fd6a03d680c668acae7f6db40ad7f5d9951a267cdf7e7686f66f751f91cece17): Bind for 0.0.0.0:8080 failed: port is already allocated

and when i try to kill 3306 cause of crashing Docker application

sudo kill `sudo lsof -t -i:3306`

enter image description here

LaraDock configuration:

...
ports:
        - "${MYSQL_PORT}:3306"
...
ports:
        - "${MARIADB_PORT}:3306"

Solution

  • You should guarantee that MYSQL_PORT and MARIADB_PORT have different values, otherwise Docker will try to allocate the same port for both on host network.

    Beside that, when you don't "publish" any port, containers on Docker can run with their own ports, like a lot of containers running with port 80, because, by default, every container has a network interface.

    Pay attention on indentation, always use spaces instead of tabs:

    ...
    version: '3.0'
    
    services:
      mysql:
        image: mysql:5.7
        ports:
        - "3306:3306"
      mariadb:
        image: mariadb:10.4
        ports:
        - "3307:3306"