Docker with mysql and django. Connection to mysql is refused despite any attempts
up vote
0
down vote
favorite
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:
- Move everything into one docker-compose file
- Get rid of "networks" entry completely
- Change hosts to
ivsdb / 127.0.0.1 / localhost / 0.0.0.0
Things that work:
- Djago service runs well
- 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
add a comment |
up vote
0
down vote
favorite
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:
- Move everything into one docker-compose file
- Get rid of "networks" entry completely
- Change hosts to
ivsdb / 127.0.0.1 / localhost / 0.0.0.0
Things that work:
- Djago service runs well
- 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
You can first try to debug this by ssh/exec into the Django container and test you can connect to the port theredocker 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 also10001
?
– 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
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
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:
- Move everything into one docker-compose file
- Get rid of "networks" entry completely
- Change hosts to
ivsdb / 127.0.0.1 / localhost / 0.0.0.0
Things that work:
- Djago service runs well
- 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
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:
- Move everything into one docker-compose file
- Get rid of "networks" entry completely
- Change hosts to
ivsdb / 127.0.0.1 / localhost / 0.0.0.0
Things that work:
- Djago service runs well
- 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
mysql django docker docker-compose connection-refused
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 theredocker 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 also10001
?
– 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
add a comment |
You can first try to debug this by ssh/exec into the Django container and test you can connect to the port theredocker 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 also10001
?
– 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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
DEFAULT_DB_PORT=10001
should actually be MySQL's default port (3306), not the host-mapped port (10001)
The difference is nicely explained here
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
add a comment |
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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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