I have a Docker file trying to deploy Django code to a container
FROM ubuntu:latest MAINTAINER { myname } #RUN echo "deb http://archive.ubuntu.com/ubuntu/ $(lsb_release -sc) main universe" >> /etc/apt/sou$ RUN apt-get update RUN DEBIAN_FRONTEND=noninteractive apt-get install -y tar git curl dialog wget net-tools nano buil$ RUN DEBIAN_FRONTEND=noninteractive apt-get install -y python python-dev python-distribute python-p$ RUN mkdir /opt/app WORKDIR /opt/app #Pull Code RUN git clone [email protected]/{user}/{repo} RUN pip install -r website/requirements.txt #EXPOSE = ["8000"] CMD python website/manage.py runserver 0.0.0.0:8000
And then I build my code as docker build -t dockerhubaccount/demo:v1 .
, and this pulls my code from Bitbucket to the container. I run it as docker run -p 8000:8080 -td felixcheruiyot/demo:v1
and things appear to work fine.
Now I want to update the code i.e since I used git clone ...
, I have this confusion:
Even if you are running your project on Docker, you can still access your git account inside Docker Containers. All you need to do is just install Git inside your Docker Container.
You can use the docker pull command to install a docker image from GitHub Packages, replacing OWNER with the name of the user or organization account that owns the repository, REPOSITORY with the name of the repository containing your project, IMAGE_NAME with name of the package or image, HOSTNAME with the host name of ...
There are a couple of approaches you can use.
docker build --no-cache
to avoid using the cache of the Git clone.git pull
. So instead of running python manage.py
, you'd have something like CMD cd /repo && git pull && python manage.py
or use a start script if things are more complex.I tend to prefer 2. You can also run a cron job to update the code in your container, but that's a little more work and goes somewhat against the Docker philosophy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With