Comments (5)
Did you make any changes to the Dockerfile, Docker Compose file, or entrypoint script?
from django-on-docker.
Same as yours.
I made a change to a file in Django template.
Why does the build process do everything from the beginning.
deleting db in each build process.
very bad. :)
Dockerfile.prod
###########
# BUILDER #
###########
# pull official base image
FROM python:3.8.0-alpine as builder
# set work directory
WORKDIR /usr/src/myapp
# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
# install psycopg2 dependencies
RUN apk update \
&& apk add postgresql-dev gcc python3-dev musl-dev
# lint
RUN pip install --upgrade pip
COPY . /usr/src/myapp/
# install dependencies
COPY ./req.txt /usr/src/myapp/req.txt
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/myapp/wheels -r req.txt
#########
# FINAL #
#########
# pull official base image
FROM python:3.8.0-alpine
# create directory for the app user
RUN mkdir -p /home/myapp
# create the app user
RUN addgroup -S myapp && adduser -S myapp -G myapp
# create the appropriate directories
ENV HOME=/home/myapp
ENV APP_HOME=/home/myapp/web
RUN mkdir $APP_HOME
WORKDIR $APP_HOME
# install dependencies
RUN apk update && apk add libpq
COPY --from=builder /usr/src/myapp/wheels /wheels
COPY --from=builder /usr/src/myapp/req.txt .
RUN pip install --upgrade pip
RUN pip install --no-cache /wheels/*
# copy entrypoint-prod.sh
COPY ./entrypoint.prod.sh $APP_HOME
# copy project
COPY . $APP_HOME
# chown all the files to the app user
RUN chown -R myapp:myapp $APP_HOME
# change to the app user
USER myapp
# run entrypoint.prod.sh
ENTRYPOINT ["/home/myapp/web/entrypoint.prod.sh"]
docker-compose.prod.yml*
version: '3.7'
services:
web:
build:
context: .
dockerfile: Dockerfile.prod
command: gunicorn myapp.wsgi:application --bind 0.0.0.0:8000
ports:
- 8000:8000
env_file:
- ./.env.prod
depends_on:
- db
db:
image: postgres:12.0-alpine
volumes:
- postgres_data:/var/lib/postgresql/data/
env_file:
- ./.env.prod.db
volumes:
postgres_data:
from django-on-docker.
Why do you think the DB is being deleted?
If you didn't change any of the code, and as long as the volume is being created properly, then the DB data should persist. Can you verify that the Postgres volume is being created?
from django-on-docker.
Thank you for your answer.
No problem. Everything is OK. :)
I need help with something.
built the code
docker-compose -f docker-compose.prod.yml build
and run
docker-compose -f docker-compose.prod.yml up -d
everything is OK
There was a change in the my code.
I need to build it for this to happen on the server.
When I build it, it re-installs pip packs. Is there a way to just load codes?
from django-on-docker.
Yes, you'll have to reorganize the Dockerfile though.
I mention caching in the blog post. See https://mherman.org/presentations/dockercon-2018/#46 as well. If you're in development you shouldn't be using the prod Docker Compose file.
from django-on-docker.
Related Issues (20)
- Why collectstatic on dev? HOT 1
- Where is certbot and Lets Encrypt? HOT 1
- How to integrate https letsencript HOT 1
- Flake 8 in app/Dockerfile.prod HOT 1
- Entrypoint files break build (container start) when they have Win CR/LF EOLs
- nginx - docker - problem with adding add worker_connections. nginx - directive is not allowed here HOT 1
- Intermittent 502 Errors When Customizing Dockerized Django / Gunicorn / Docker / Postgres HOT 6
- Conflict between dev and prod HOT 1
- Getting stuck on "Media files"
- Not serving static files
- unable to create migration file HOT 2
- Dockerfile missing netcat dependency (apologies if wrong repo for django-tdd-docker) HOT 1
- Please mention the database flush in the Readme HOT 1
- Volumes attached, but no tables in hello_django_dev DB HOT 1
- Copy overrides entrypoint.sh HOT 5
- nginx does not start... HOT 8
- Debug Flag as bool HOT 1
- Entrypoint script not found HOT 1
- Not suitable for production without supervisor process?
- Making media files accessible from host HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-on-docker.