Error starting userland proxy: listen tcp 0.0.0.0:3306: bind: address already in


#1

Hi there,

I am using a docker-compose file that runs my dockerized app and a MySql DB.
The MySql Image exposes port 3306, however I keep getting this error when trying to bring it up:

ERROR: for db  Cannot start service db: driver failed programming external connectivity on endpoint myrepo_db_1 (dc420fc36e196cfa9ac1e4ed70bf1a513fad39231ba11f0d05b6d16d066551c0): Error starting userland proxy: listen tcp 0.0.0.0:3306: bind: address already in use
ERROR: Encountered errors while bringing up the project.

My suspition is that CircleCI already has a MySql instance runnign to “help” me. Is there a way I can disable it?

I am using the Ruby 2.3 base image on the DockerExecutor.

version: 2
executorType: docker
jobs:
  build:
    docker:
      - image: ruby:2.3

#2

You can run netstat -plntua or ss -plntua to check open ports but it’s not running by default.

Do you have the necessary dependencies installed? I advise building your own base image.


#3

I’ll check the result of netstat -plntua. About the dependencies, The only thing I need is docker and docker-compose, as well as ruby and gem to install a deployment CLI (kontena).


#4

So the output of ss-plntua is the following:

ss -plntua
Shell: /bin/bash -eo pipefail

Netid  State      Recv-Q Send-Q     Local Address:Port       Peer Address:Port 
udp    UNCONN     0      0             127.0.0.11:57903                 *:*     
tcp    LISTEN     0      128           127.0.0.11:51700                 *:*     
tcp    TIME-WAIT  0      0             172.19.0.3:52807    192.30.253.112:22    
tcp    ESTAB      0      0             172.19.0.3:56669        172.19.0.2:5500   users:(("picard",pid=13,fd=4))
tcp    TIME-WAIT  0      0             172.19.0.3:33550      52.85.142.31:443   
tcp    TIME-WAIT  0      0             172.19.0.3:54745    192.30.253.113:22    

The port is not in use, but somehow I still get the error. Any idea what might be causing it?


#5

What do you get from docker ps -a before spinning up your MySQL container?


#6

Not much unfortunately.

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES

However I am spinning up my containers using docker-compose up -d --force-recreate. Could the --force-recreate have an impact on the underlying build env?


#7

I guess so if you’re hitting that error


#8

I tried again without --force-recreate and still get the error.
Could any of you try to see if you can reproduce the error? This docker-compose command is running fine on all other CIs tools I am trying atm.

Below is my docker-compose.yml, the app in itself does not matter much since the linked db service won’t start.

Here is a minimal config that I use to reproduce:

config.yml

version: 2
executorType: docker
jobs:
  build:
    docker:
      - image: ruby:2.3
    working_directory: ~/12grapes
    steps:
      - checkout
      - setup_docker_engine
      # This should go into custom primary image, here's only for the sake of explanation
      - run:
          name: Install Docker client
          command: |
            set -x
            VER="17.03.0-ce"
            curl -L -o /tmp/docker-$VER.tgz https://get.docker.com/builds/Linux/x86_64/docker-$VER.tgz
            tar -xz -C /tmp -f /tmp/docker-$VER.tgz
            mv /tmp/docker/* /usr/bin
      - run:
          name: Install Docker Compose
          command: |
            set -x
            curl -L https://github.com/docker/compose/releases/download/1.11.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
            chmod +x /usr/local/bin/docker-compose
      - run: ss -plntua
      - run: docker ps -a
      - run: docker-compose up -d

docker-compose.yml

version: '2'
services:
  db:
    image: mysql:5.7.7
    expose:
        - '3306'
    ports:
        - "3306:3306"
  app:
    build:
      context: .
      dockerfile: Dockerfile
    links:
      - db

#10

@superzadeh the problem was in our image we are using for Remote Docker, we’ve fixed it, you should be able to run your build now.

Side note, to give some perspective why ss -plntua didn’t show anything using port 3306 - all the commands are executed in your primary container (ruby:2.3) at the same time containers you are starting with docker-compose are running in Remote Docker Environment. You can read more in our docs.


#11

@smaantci Thanks for the reply, I’ll give this another shot later since for now I have moved to another CI tool.

The explanation makes perfect sense. Maybe detailing more what’s running in the image of the Remote Docker environment would help in troubleshooting these issues.


#12