GithubHelp home page GithubHelp logo

Comments (5)

mjhea0 avatar mjhea0 commented on July 22, 2024

Did you make any changes to the Dockerfile, Docker Compose file, or entrypoint script?

from django-on-docker.

basitiyidir avatar basitiyidir commented on July 22, 2024

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.

mjhea0 avatar mjhea0 commented on July 22, 2024

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.

basitiyidir avatar basitiyidir commented on July 22, 2024

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.

mjhea0 avatar mjhea0 commented on July 22, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.