So i have some django webb projects and now its time to get my django apps prod ready with docker.
My plan is to with jenkins build my django apps (soon start a docker of the app and run some test but that will be later) make a docker image and send that to the docker cloud.
Then a can download the docker image on my prod server and start the app. I hope that this also can be triggerd from my jenkins so the flow will be
me ->push github master -> jenkins make build and docker image -> push up to dockercloud -> prodserver gets image and deploy to server
And i would like this flow to start from my push to the master branch in github. So my masterpush gets my data from dev to prod.
First task is to make a dockerfile to use for my app.
In the base django app i created a folder called Docker and put the dockerfile there.
1. I use centos7 as base
2. I have e file in called req.sh that contains all my pip req for my project
3. I have i defult settings file for my django project that I use in the docker build(Match this to you own settings).
I also have the plan to mount static content from the host into the docker image so that is in the dockerfile but not activated.
Here is the link to my dockerfile
to build the image i use
sudo docker build -t mattiashem/theguide --no-cache .
And to run to test the server in DEV MODE use.
sudo docker run -i -p 8080:8080 mattiashem/theguide python /var/www/asylguiden/manage.py runserver 0.0.0.0:8080
And to run the server in prod mode use
docker run -d -p 8000:8000 mattiashem/theguide /var/www/asylguiden/Docker/start_prod.sh
I use gunicorn as prodserver for djangoproject and i have a small bash script that will start the app.
(questions about media and server check out next post when I setup the prod servers)
Now we should have a working docker running on our localserver lets get into the dockercloud
sudo docker login
sudo docker push mattiashem/theguide
And now we have build our app and push it to the dockercloud ready to be used.
2. Getting jenkins to build my app and make the dockerimage and push it upto the docker cloud.
First lets fix sudo for the jenkins user so we can use docker.
fix this make the jenkins user allow to run docker and dont req tty
jenkins ALL=(docker) NOPASSWD: ALL
login to the dockercloud with
Now the server is ready to build the dockerimage. Start i new project and make it checkout you code and set other settings.
Then in the last “exchute shell” past something like this in
echo "Building docker image" pwd cd Docker pwd echo "Buildning docker image" sudo docker build -t mattiashem/theguide --no-cache . sudo docker push mattiashem/theguide
This will now build the docker image and the push the new build image to the dockercloud ready to be used.
3. To to
Fix so that the jenkins server start a dockerimage and then perform some test on the new dockerbuild.