I am currently using this Dockerfile to build my backend service:
FROM python:3.9-buster
ENV PYTHONUNBUFFERED 1
WORKDIR /app
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
COPY . /app
CMD python manage.py runserver 0.0.0.0:8002
I also have a mysql database the Docker-compose file is:
version: '3.8'
services:
dj:
build:
context: .
dockerfile: Dockerfile
ports:
- 8000:8002
volumes:
- .:/app
depends_on:
- db
db:
image: mysql:5.7.22
restart: always
environment:
MYSQL_DATABASE: ...
MYSQL_USER: ...
MYSQL_PASSWORD: ...
MYSQL_ROOT_PASSWORD: ...
volumes:
- .dbdata:/var/lib/mysql
ports:
- 33068:3306
I want to reduce the size of my container which is currently 1.2G any detailed explanation on how to do that would be helpful, precisely I want to know how to do a multisatge build or use a lighter base image properly because I looked at some blogs that use the alpine as their base image but that doesn't work for me probably because my requirement.txt:
Django==3.1.3
djangorestframework==3.12.2
django-cors-headers==3.5.0
djangorestframework-simplejwt==4.7.1
pyjwt==2.1.0
mysqlclient==2.0.1
django-mysql==3.9
is not enough.