0

So far I have tried everything I could find on the internet - but nothing seems to help.

This is my docker-compose.yml file:

version: '3.3'

services:
  ivs_fraud:
    build:
      context: .
      args:
        GIT_SSH_KEY: ${GIT_SSH_KEY}
    image: ivs_fraud:latest
    container_name: fraud
    depends_on:
      - ivsdb
    links:
      - ivsdb
    networks:
      - database_network

networks:
  database_network:
    driver: bridge

And I have a link / dependency to ivsdb service which is defined in another docker-compose-dev.yml file:

version: '3.3'

services:
  ivsdb:
    image: mysql
    container_name: ivsdb
    networks:
      - database_network
    ports:
      - ${DEFAULT_DB_PORT}:3306
    restart: always
    environment:
      MYSQL_DATABASE: ${DEFAULT_DB_NAME}
      MYSQL_USER: ${DEFAULT_DB_USER}
      MYSQL_PASSWORD: ${DEFAULT_DB_PASS}
      MYSQL_ROOT_PASSWORD: ${DEFAULT_DB_ROOT_PASS}

This is my .env file (Django reads this .env file and creates a connection according to it):

DEFAULT_DB_NAME=ivsdb
DEFAULT_DB_HOST=ivsdb
DEFAULT_DB_PORT=10001
DEFAULT_DB_USER=root
DEFAULT_DB_PASS=root
DEFAULT_DB_ROOT_PASS=root

And i keep getting:

(2003, 'Can\'t connect to MySQL server on \'ivsdb\' (111 "Connection refused")')

There are several modifications that i have tried with no success:

  1. Move everything into one docker-compose file
  2. Get rid of "networks" entry completely
  3. Change hosts to ivsdb / 127.0.0.1 / localhost / 0.0.0.0

Things that work:

  1. Djago service runs well
  2. Mysql service runs well.

I can connect to it using command line:

mysql -uroot -proot -P10001 --protocol=tcp 

or

mysql -uroot -proot -P10001 -h127.0.0.1 (IP adress enforces tcp protocol)

Looks like Django is having some hard time connecting to mysql container. But judging by "Connection refused" - django can reach mysql container.

What am I missing?

3
  • You can first try to debug this by ssh/exec into the Django container and test you can connect to the port there docker exec -it ivs_fraud bash Commented Nov 9, 2018 at 12:14
  • Is the port that Django is configured and trying to connect to for MySQL also 10001? Commented Nov 9, 2018 at 12:17
  • 1
    Yes. It Django is definitely looking to the 10001 port. Commented Nov 9, 2018 at 12:48

1 Answer 1

2

DEFAULT_DB_PORT=10001 should actually be MySQL's default port (3306), not the host-mapped port (10001)

The difference is nicely explained here

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

3 Comments

So as I understand I was specifying the port for the host (10001) but not for my services. So if I want those services to also be linked to 10001 i should use "expose" keyword additionally ?
By the way. It fixed the problem. Thank you.
You cannot have mapping for expose, it takes only a single argument.. So, you could expose 10001, but it wouldn't be of much use, because MySQL would be still listening on 3306. So, to achieve what you wanted to you would have to also change the listening port for MySQL as well.

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.