Docker with mysql and django. Connection to mysql is refused despite any attempts











up vote
0
down vote

favorite
1












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?










share|improve this question






















  • 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
    – A Star
    Nov 9 at 12:14










  • Is the port that Django is configured and trying to connect to for MySQL also 10001?
    – A Star
    Nov 9 at 12:17






  • 1




    Yes. It Django is definitely looking to the 10001 port.
    – Laimonas Sutkus
    Nov 9 at 12:48















up vote
0
down vote

favorite
1












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?










share|improve this question






















  • 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
    – A Star
    Nov 9 at 12:14










  • Is the port that Django is configured and trying to connect to for MySQL also 10001?
    – A Star
    Nov 9 at 12:17






  • 1




    Yes. It Django is definitely looking to the 10001 port.
    – Laimonas Sutkus
    Nov 9 at 12:48













up vote
0
down vote

favorite
1









up vote
0
down vote

favorite
1






1





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?










share|improve this question













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?







mysql django docker docker-compose connection-refused






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 9 at 8:57









Laimonas Sutkus

358110




358110












  • 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
    – A Star
    Nov 9 at 12:14










  • Is the port that Django is configured and trying to connect to for MySQL also 10001?
    – A Star
    Nov 9 at 12:17






  • 1




    Yes. It Django is definitely looking to the 10001 port.
    – Laimonas Sutkus
    Nov 9 at 12:48


















  • 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
    – A Star
    Nov 9 at 12:14










  • Is the port that Django is configured and trying to connect to for MySQL also 10001?
    – A Star
    Nov 9 at 12:17






  • 1




    Yes. It Django is definitely looking to the 10001 port.
    – Laimonas Sutkus
    Nov 9 at 12:48
















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
– A Star
Nov 9 at 12:14




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
– A Star
Nov 9 at 12:14












Is the port that Django is configured and trying to connect to for MySQL also 10001?
– A Star
Nov 9 at 12:17




Is the port that Django is configured and trying to connect to for MySQL also 10001?
– A Star
Nov 9 at 12:17




1




1




Yes. It Django is definitely looking to the 10001 port.
– Laimonas Sutkus
Nov 9 at 12:48




Yes. It Django is definitely looking to the 10001 port.
– Laimonas Sutkus
Nov 9 at 12:48












1 Answer
1






active

oldest

votes

















up vote
2
down vote



accepted










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



The difference is nicely explained here






share|improve this answer





















  • 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 ?
    – Laimonas Sutkus
    Nov 9 at 12:55










  • By the way. It fixed the problem. Thank you.
    – Laimonas Sutkus
    Nov 9 at 12:56






  • 1




    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.
    – Uku Loskit
    Nov 9 at 12:58











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222552%2fdocker-with-mysql-and-django-connection-to-mysql-is-refused-despite-any-attempt%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
2
down vote



accepted










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



The difference is nicely explained here






share|improve this answer





















  • 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 ?
    – Laimonas Sutkus
    Nov 9 at 12:55










  • By the way. It fixed the problem. Thank you.
    – Laimonas Sutkus
    Nov 9 at 12:56






  • 1




    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.
    – Uku Loskit
    Nov 9 at 12:58















up vote
2
down vote



accepted










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



The difference is nicely explained here






share|improve this answer





















  • 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 ?
    – Laimonas Sutkus
    Nov 9 at 12:55










  • By the way. It fixed the problem. Thank you.
    – Laimonas Sutkus
    Nov 9 at 12:56






  • 1




    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.
    – Uku Loskit
    Nov 9 at 12:58













up vote
2
down vote



accepted







up vote
2
down vote



accepted






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



The difference is nicely explained here






share|improve this answer












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



The difference is nicely explained here







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 12:18









Uku Loskit

29.5k76779




29.5k76779












  • 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 ?
    – Laimonas Sutkus
    Nov 9 at 12:55










  • By the way. It fixed the problem. Thank you.
    – Laimonas Sutkus
    Nov 9 at 12:56






  • 1




    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.
    – Uku Loskit
    Nov 9 at 12:58


















  • 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 ?
    – Laimonas Sutkus
    Nov 9 at 12:55










  • By the way. It fixed the problem. Thank you.
    – Laimonas Sutkus
    Nov 9 at 12:56






  • 1




    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.
    – Uku Loskit
    Nov 9 at 12:58
















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 ?
– Laimonas Sutkus
Nov 9 at 12:55




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 ?
– Laimonas Sutkus
Nov 9 at 12:55












By the way. It fixed the problem. Thank you.
– Laimonas Sutkus
Nov 9 at 12:56




By the way. It fixed the problem. Thank you.
– Laimonas Sutkus
Nov 9 at 12:56




1




1




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.
– Uku Loskit
Nov 9 at 12:58




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.
– Uku Loskit
Nov 9 at 12:58


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53222552%2fdocker-with-mysql-and-django-connection-to-mysql-is-refused-despite-any-attempt%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)