Dockerfile django & mysql
I'm trying to create a docker environment for my django project
my dockerfile :
FROM python:3
ENV PYTHONUNBUFFERED=1
RUN apt-get install default-libmysqlclient-dev
RUN mkdir /config
ADD /config/requirements.txt /config/
RUN pip install -r /config/requirements.txt
RUN mkdir /src
WORKDIR /src
my docker-compose :
version: '3'
services:
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_DATABASE: ProjetDjango
container_name: mysql01
restart: always
nginx:
image: nginx:1.13-alpine
container_name: nginx01
ports:
- "8000:8000"
volumes:
- ./project:/src
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- web
web:
build: .
container_name: django01
command: bash -c "python3 manage.py makemigrations && python3 manage.py migrate && python3 manage.py collectstatic --noinput && gunicorn hello_django.wsgi -b 0.0.0.0:8000"
depends_on:
- db
volumes:
- ./project:/src
expose:
- "8000"
restart: always
my settings.py :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ProjetDjango',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
I've got this error while running : docker-compose up
django.db.utils.OperationalError: (2006, 'Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")')
django01 exited with code 1
I've been working on this issue for 2 days now and didn't find a response that solve it!
Thank you for your help
mysql django docker
add a comment |
I'm trying to create a docker environment for my django project
my dockerfile :
FROM python:3
ENV PYTHONUNBUFFERED=1
RUN apt-get install default-libmysqlclient-dev
RUN mkdir /config
ADD /config/requirements.txt /config/
RUN pip install -r /config/requirements.txt
RUN mkdir /src
WORKDIR /src
my docker-compose :
version: '3'
services:
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_DATABASE: ProjetDjango
container_name: mysql01
restart: always
nginx:
image: nginx:1.13-alpine
container_name: nginx01
ports:
- "8000:8000"
volumes:
- ./project:/src
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- web
web:
build: .
container_name: django01
command: bash -c "python3 manage.py makemigrations && python3 manage.py migrate && python3 manage.py collectstatic --noinput && gunicorn hello_django.wsgi -b 0.0.0.0:8000"
depends_on:
- db
volumes:
- ./project:/src
expose:
- "8000"
restart: always
my settings.py :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ProjetDjango',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
I've got this error while running : docker-compose up
django.db.utils.OperationalError: (2006, 'Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")')
django01 exited with code 1
I've been working on this issue for 2 days now and didn't find a response that solve it!
Thank you for your help
mysql django docker
add a comment |
I'm trying to create a docker environment for my django project
my dockerfile :
FROM python:3
ENV PYTHONUNBUFFERED=1
RUN apt-get install default-libmysqlclient-dev
RUN mkdir /config
ADD /config/requirements.txt /config/
RUN pip install -r /config/requirements.txt
RUN mkdir /src
WORKDIR /src
my docker-compose :
version: '3'
services:
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_DATABASE: ProjetDjango
container_name: mysql01
restart: always
nginx:
image: nginx:1.13-alpine
container_name: nginx01
ports:
- "8000:8000"
volumes:
- ./project:/src
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- web
web:
build: .
container_name: django01
command: bash -c "python3 manage.py makemigrations && python3 manage.py migrate && python3 manage.py collectstatic --noinput && gunicorn hello_django.wsgi -b 0.0.0.0:8000"
depends_on:
- db
volumes:
- ./project:/src
expose:
- "8000"
restart: always
my settings.py :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ProjetDjango',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
I've got this error while running : docker-compose up
django.db.utils.OperationalError: (2006, 'Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")')
django01 exited with code 1
I've been working on this issue for 2 days now and didn't find a response that solve it!
Thank you for your help
mysql django docker
I'm trying to create a docker environment for my django project
my dockerfile :
FROM python:3
ENV PYTHONUNBUFFERED=1
RUN apt-get install default-libmysqlclient-dev
RUN mkdir /config
ADD /config/requirements.txt /config/
RUN pip install -r /config/requirements.txt
RUN mkdir /src
WORKDIR /src
my docker-compose :
version: '3'
services:
db:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_USER: root
MYSQL_PASSWORD: root
MYSQL_DATABASE: ProjetDjango
container_name: mysql01
restart: always
nginx:
image: nginx:1.13-alpine
container_name: nginx01
ports:
- "8000:8000"
volumes:
- ./project:/src
- ./config/nginx:/etc/nginx/conf.d
depends_on:
- web
web:
build: .
container_name: django01
command: bash -c "python3 manage.py makemigrations && python3 manage.py migrate && python3 manage.py collectstatic --noinput && gunicorn hello_django.wsgi -b 0.0.0.0:8000"
depends_on:
- db
volumes:
- ./project:/src
expose:
- "8000"
restart: always
my settings.py :
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ProjetDjango',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
I've got this error while running : docker-compose up
django.db.utils.OperationalError: (2006, 'Can't connect to MySQL server on '127.0.0.1' (111 "Connection refused")')
django01 exited with code 1
I've been working on this issue for 2 days now and didn't find a response that solve it!
Thank you for your help
mysql django docker
mysql django docker
edited Jan 19 at 14:28
Khashayar Ghamati
10018
10018
asked Jan 19 at 13:51
Zineb LazrakZineb Lazrak
31
31
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
When you link your db service to your web service in docker so you must use your db service name instead of your database server ip for connecting database :
db:
image: mysql
restart: unless-stopped
container_name: db_of_my_project
web:
build: .
container_name: django01
command: ...
links:
- db
volumes:
- ./project:/src
expose:
- "8000"
restart: always
and your database configuration:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ProjetDjango',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'db', # database container name
'PORT': '',
}
}
1
(This answer will work equally well without thelinks:section.)
– David Maze
Jan 19 at 17:44
add a comment |
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',
autoActivateHeartbeat: false,
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
});
}
});
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%2f54267781%2fdockerfile-django-mysql%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
When you link your db service to your web service in docker so you must use your db service name instead of your database server ip for connecting database :
db:
image: mysql
restart: unless-stopped
container_name: db_of_my_project
web:
build: .
container_name: django01
command: ...
links:
- db
volumes:
- ./project:/src
expose:
- "8000"
restart: always
and your database configuration:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ProjetDjango',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'db', # database container name
'PORT': '',
}
}
1
(This answer will work equally well without thelinks:section.)
– David Maze
Jan 19 at 17:44
add a comment |
When you link your db service to your web service in docker so you must use your db service name instead of your database server ip for connecting database :
db:
image: mysql
restart: unless-stopped
container_name: db_of_my_project
web:
build: .
container_name: django01
command: ...
links:
- db
volumes:
- ./project:/src
expose:
- "8000"
restart: always
and your database configuration:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ProjetDjango',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'db', # database container name
'PORT': '',
}
}
1
(This answer will work equally well without thelinks:section.)
– David Maze
Jan 19 at 17:44
add a comment |
When you link your db service to your web service in docker so you must use your db service name instead of your database server ip for connecting database :
db:
image: mysql
restart: unless-stopped
container_name: db_of_my_project
web:
build: .
container_name: django01
command: ...
links:
- db
volumes:
- ./project:/src
expose:
- "8000"
restart: always
and your database configuration:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ProjetDjango',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'db', # database container name
'PORT': '',
}
}
When you link your db service to your web service in docker so you must use your db service name instead of your database server ip for connecting database :
db:
image: mysql
restart: unless-stopped
container_name: db_of_my_project
web:
build: .
container_name: django01
command: ...
links:
- db
volumes:
- ./project:/src
expose:
- "8000"
restart: always
and your database configuration:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'ProjetDjango',
'USER': 'root',
'PASSWORD': 'root',
'HOST': 'db', # database container name
'PORT': '',
}
}
edited Jan 27 at 8:03
answered Jan 19 at 14:04
Khashayar GhamatiKhashayar Ghamati
10018
10018
1
(This answer will work equally well without thelinks:section.)
– David Maze
Jan 19 at 17:44
add a comment |
1
(This answer will work equally well without thelinks:section.)
– David Maze
Jan 19 at 17:44
1
1
(This answer will work equally well without the
links: section.)– David Maze
Jan 19 at 17:44
(This answer will work equally well without the
links: section.)– David Maze
Jan 19 at 17:44
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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%2f54267781%2fdockerfile-django-mysql%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