Reputation: 397
I'm relatively new to Docker/deployment in general.
I have a django app that utilizes rpy2 (not sure if relevant), that I have deployed using a docker container. However, I want to be able to continue developing the application and testing within the docker environment without having to spin the container up and down constantly.
I read that using volumes could help to bring this functionality back, but I either have gotten the container working and don't see updates, or I get errors saying that manae.py can't be found.
Is there any way to reintroduce the autoloading functionality?
Here is my Dockerfile:
FROM rocker/r-ver:4.1.1
ENV RENV_VERSION 0.14.0
# Install system dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
build-essential \
python3-pip \
python3-setuptools \
python3-dev \
libcurl4-openssl-dev \
libssl-dev \
libfontconfig1-dev \
libxml2-dev \
libharfbuzz-dev \
libfribidi-dev \
libfreetype6-dev \
libpng-dev \
libtiff5-dev \
libjpeg-dev \
libbz2-dev \
libopenblas-dev \
unixodbc-dev \
libcairo2-dev \
zlib1g-dev \
curl \
libpq-dev
RUN apt-get update && apt-get install -y cmake
RUN apt-get install -y --no-install-recommends libxt6
WORKDIR /app
COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt
RUN R -e "install.packages('remotes')"
RUN R -e "remotes::install_github('rstudio/renv@${RENV_VERSION}')"
COPY renv.lock renv.lock
RUN R -e "renv::restore()"
RUN R_HOME=$(R RHOME) && echo "R_HOME=$R_HOME" && export R_HOME
ENV R_HOME=${R_HOME}
COPY custom_package.tar.gz custom_package.tar.gz
RUN R -e "remotes::install_local('custom_package.tar.gz', dependencies = F, force = T, upgrade = 'never')"
RUN R -e "install.packages('glmnet')"
## Expose port to allow app to run locally
EXPOSE 8000
COPY . .
CMD ["python3","manage.py","runserver", "0.0.0.0:8000"]
This is my docker-compose file:
version: '3.8'
services:
django:
image: django-docker:0.0.1
build: .
ports:
- "8000:8000"
environment:
- DEBUG=1
Upvotes: 0
Views: 867
Reputation: 836
Yes you can. Just map the volume of your app directory and your development server will auto reload depending on your file changes just as if you were developing in a standard python virtual environment.
version: '3.8'
services:
django:
image: django-docker:0.0.1
build:
context: './app'
ports:
- "8000:8000"
environment:
- DEBUG=1
volumes:
- "./app:/app"
Just some slight changes to your docker compose config. In this configuration, the docker-compose.yaml
is in the root directory of the project. The entire Django project
and its Dockerfile
is in folder called app
within the project root directory.
The key is mapping the volumes "./app:/app".
Upvotes: 0