3

Docker version 17.03.1-ce, build c6d412e OS: Ubuntu

I am trying to connect to host mysql from the docker container. but i am getting this error.

Error: connect ECONNREFUSED 0.0.0.0:3306

I am getting same for mysql if i use mysql container. Tried 127.0.0.1 and localhost also.

version: '2'

services:

### Applications Code Container 
#############################

  applications:
    image: tianon/true
    volumes:
      - ${APPLICATION}:/var/www/html

  apache2:
    build:
      context: ./apache2
    volumes_from:
      - applications
    volumes:
      - ${APACHE_HOST_LOG_PATH}:/var/log/apache2
      - ./apache2/sites:/etc/apache2/sites-available
    ports:
      - "${APACHE_HOST_HTTP_PORT}:80"
      - "${APACHE_HOST_HTTPS_PORT}:443"
    networks:
      - frontend
      - backend

  node:
    build:
      context: ./node
    volumes_from:
      - applications
    ports:
      - "4000:30001"
    networks:
      - frontend
      - backend    


### MySQL Container  #########################################

  mysql:
    build:
      context: ./mysql
    environment:
      - MYSQL_DATABASE=${MYSQL_DATABASE}
      - MYSQL_USER=${MYSQL_USER}
      - MYSQL_PASSWORD=${MYSQL_PASSWORD}
      - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
    volumes_from:
      - applications  
    volumes:
      - ${DATA_SAVE_PATH}/mysql:/var/lib/mysql
      - ./mysql/docker-entrypoint-initdb.d:/docker-entrypoint-initdb.d
    ports:
      - "${MYSQL_PORT}:3306"
    networks:
      - backend


### Networks Setup ############################################

networks:
  frontend:
    driver: "bridge"
  backend:
    driver: "bridge"

### Volumes Setup #############################################

volumes:
  mysql:
    driver: "local"
  mongo:
    driver: "local"
  node:
    driver: "local"
  apache2:
    driver: "local"
17
  • What port binding you see with docker-compose ps for mysql? Commented Jun 1, 2017 at 16:35
  • 0.0.0.0:3306->3306/tcp for mysql container. Commented Jun 1, 2017 at 16:37
  • I am more concerned about connecting with docker host mysql, creating a mysql container was just a try. Commented Jun 1, 2017 at 16:38
  • Oh.. I understand. Use this: 172.17.0.1:3306. That IP is fixed for your host docker, visible from container. Give a try Commented Jun 1, 2017 at 16:40
  • Nope. not working. I am also connecting to the mongo db. Which is on another server. That is working. Commented Jun 1, 2017 at 16:44

1 Answer 1

0

Instead of using 0.0.0.0, 127.0.0.1 or localhost, you should use your host machine's IP. This is because each container is a individual node in the network.

Or if you can inspect your MySQL container, and get the IP of it, you can use the IP as well, since they are on the same network.

Sign up to request clarification or add additional context in comments.

1 Comment

@Sandhu I see you are building the mysql. Can you provide the mysql log? docker-compose logs mysql. I suspect if the mysql is running, or bind to an ip.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.