Skip to content

Commit 24d0ed8

Browse files
committed
[TM-29] Containerize the application using docker and docker-compose
1 parent d14f5ad commit 24d0ed8

5 files changed

Lines changed: 71 additions & 1 deletion

File tree

.dockerignore

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
__pycache__/
2+
*.pyc
3+
*.pyo
4+
*.db
5+
.env
6+
.dockerenv
7+
.git
8+
.gitignore
9+
venv/
10+
node_modules/
11+
media/

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
venv/
22
.env
3+
.dockerenv

Dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM python:3.10-slim
2+
3+
ENV PYTHONDONTWRITEBYTECODE 1
4+
ENV PYTHONUNBUFFERED 1
5+
6+
WORKDIR /app
7+
8+
# System deps for mysqlclient build
9+
RUN apt-get update && apt-get install -y \
10+
gcc \
11+
default-libmysqlclient-dev \
12+
pkg-config \
13+
&& rm -rf /var/lib/apt/lists/*
14+
15+
COPY requirements.txt /app/
16+
17+
RUN pip install --upgrade pip && pip install -r requirements.txt && pip install gunicorn
18+
19+
COPY . /app/
20+
21+
EXPOSE 8000
22+
23+
CMD ["gunicorn", "task_manager.wsgi:application", "--bind", "0.0.0.0:8000"]
24+

docker-compose.yml

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
2+
services:
3+
db:
4+
image: mysql:8.0
5+
container_name: mysql_db
6+
restart: always
7+
environment:
8+
MYSQL_DATABASE: mydb
9+
MYSQL_USER: myuser
10+
MYSQL_PASSWORD: mypass
11+
MYSQL_ROOT_PASSWORD: root
12+
ports:
13+
- "3307:3306"
14+
volumes:
15+
- mysql_data:/var/lib/mysql
16+
web:
17+
build: .
18+
container_name: django_app
19+
command: gunicorn task_manager.wsgi:application --bind 0.0.0.0:8000
20+
volumes:
21+
- .:/app
22+
ports:
23+
- "8000:8000"
24+
env_file:
25+
- .dockerenv
26+
depends_on:
27+
- db
28+
29+
volumes:
30+
mysql_data:
31+
32+
33+
34+

task_manager/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
# SECURITY WARNING: don't run with debug turned on in production!
3434
DEBUG = os.getenv('DEBUG') == 'True'
3535

36-
ALLOWED_HOSTS = []
36+
ALLOWED_HOSTS = ['*']
3737

3838

3939
# Application definition

0 commit comments

Comments
 (0)