A Docker setup for a Django REST API with Travis CI support
docker-compose.yml
file in the app section under command enter your Django project name.env
file enter your Django project’s secret key under secret keyapp/
folderDockerfile
inside the app/
directory if you are using Python 3 uncomment the FROM python:3-onbuild
command and comment out the FROM python:2-onbuild
we are using the onbuild version so it will automatically load the requirements.txt filerequirements.txt
file append the contents of the requirements.txt
in this project to yours.settings.py
file replace your os.environ['SECRET_KEY']
True if os.getenv('DEBUG') == 'true' else False
settings.py
replace youros.environ['DB_NAME']
os.environ['DB_USER']
os.environ['DB_PASS']
os.environ['DB_HOST']
os.environ['DB_PORT']
You have made your Django project get the database and secret key data from the environment variables which are defined in the .env
file from earlier.
'*'
as one of your hosts in ALLOWED_HOSTS (don’t know if this is needed, had to do this to get it to work on my machine)psql
command under before_script docker-compose build
docker-compose up
docker-compose run app /usr/local/bin/python manage.py collectstatic
and then reload