Skip to content

Docker Deployment

Daniel Dupriest edited this page Mar 15, 2019 · 21 revisions

Docker files are provided to test and deploy Reimbursinator front end, back end, and admin services using nginx and gunicorn. Versions of tools used in the current config are as follows.

Tool/Module Version
Python 3.5
python-decouple 3.1
Django 2.1.4
Django CORS Headers 2.4.0
Django Rest Framework 3.8.2
Django Rest Authentication 0.9.3
nginx 1.10.3
gunicorn 19.6.0

The following docker containers are used in the default configuration:

Name Location Description Port
reimbursinator_front front/ Reimbursinator client html/css/js served with nginx 8443
reimbursinator_back back/ Django API backend served with gunicorn 8444
reimbursinator_admin admin/ Django admin html/css/js served with nginx 8445

Please note that with the current configuration, changes to the database only persist while the back end container is running. Everything is reset once the container is stopped. When used with Docker in production a solution including setting up mounted volumes is probably necessary.

Setup

First install Docker (or Docker Toolkit) and clone the repository. Open a Docker terminal and determine the ip of your docker machine.

docker-machine ip

Edit the ./back/reimbursinator/settings.py file and change the following lines to match the correct IP or domain name.

  • ALLOWED_HOSTS - This tells Django which front end addresses should be served.
  • CORS_ORIGIN_WHITELIST - This tells Django which front end addresses to provide CORS headers for. (include port)
  • STATIC_URL - This tells Django where admin css/js will be served from. (port 8445 by default)
  • LOGIN_URL and LOGIN_REDIRECT_URL - These should point to your front page, including port if necessary. e.g. https://192.168.99.100:8443

Building Container

Enter the root directory of the project with the docker-compose.yml file and build the image.

docker-compose build

Starting Container

docker-compose up -d to start.

nginx will serve the contents of /front/static via https on port 8443 and gunicorn will serve django API requests via https on port 8444.

Testing

The Docker image includes a self-signed SSL certificate for encryption. In order to view the pages you will need to create an exception the first time you access each server.

Access the static content at https://<machine_ip>:8443.

Access the Django API at https://<machine_ip>:8444.

Access Django admin at https://<machine_ip>:8444/admin.

Stopping Container

When you are done, stop the container.

docker-compose down

Rebuilding Image

Whenever you change any files in the project, you will probably need to rebuild. To just rebuild, run:

docker-compose build

Or, to build and start the containers (which is usually what you want to do), run:

docker-compose up -d --build

Troubleshooting

View container logs.

docker-compose logs

To get a bash prompt inside one of the containers, first get the hex name of the container:

docker container ls

Then run the bash command on the desired container.

docker exec -ti <hex_name> bash

Cleanup

After building many versions of an image you may have a lot of unused images taking up space. To see them, run:

docker image ls

You may find a lot of them are unused however. To automatically remove disconnected and unused images, etc. run:

docker system prune

Clone this wiki locally