Repository navigation
Add dockerfile - #1237
Add dockerfile#1237rcludwick wants to merge 3 commits into
Conversation
|
This should be an example of how I use docker-compose. Running In production, I use secrets, which are files that are loaded into the docker container that hold the secret bits. The only thing that doesn't happen automatically is creating the inventree database. But I just need to do that once and it's good, and it's done like so: $ docker-compose build inventree
# wait 20 minutes
$ docker-compose up -d db
# Now create the database
$ docker-compose run inventree bash
Creating dev_inventree_run ... done
bash-5.0# pgcli -h db -p 5432 -u pguser
> create database inventree;
(ctrl-D)(ctrl-D)
# Now bring up InvenTree and tail the logs.
$ docker-compose up -d
$ docker-compose logs --follow inventreeHere's a docker compose that sets the user/pw to version: "3.8"
services:
db:
image: postgres
container_name: db
ports:
- 5432/tcp
environment:
- PGDATA=/var/lib/postgresql/data/pgdb
- POSTGRES_USER=pguser
- POSTGRES_PASSWORD=pgpassword
volumes:
- /path/to/pg/data:/var/lib/postgresql/data
restart: unless-stopped
inventree:
build:
context: ./InvenTree
args:
VERSION: add-dockerfile
INVENTREE_REPO: "https://github.com/rcludwick/InvenTree.git"
image: inventree:latest
container_name: inventree
ports:
- 9767/tcp
depends_on:
- db
volumes:
- /path/to/static:/usr/src/static
- /path/to/media:/usr/src/media
environment:
# RUN MIGRATE_STATIC WHENEVER YOU UPDATE THE INVENTREE CONTAINER TO A NEW VERSION
- MIGRATE_STATIC=True
- DATABASE_NAME=inventree
# CREATE SUPERUSER ONCE THEN DELETE THESE
- CREATE_SUPERUSER=False
- DJANGO_SUPERUSER_USERNAME=admin
- [email protected]
- DJANGO_SUPERUSER_PASSWORD=admin
# SECRETS
- DATABASE_USER=pguser
- DATABASE_PASSWORD=pgpassword
- INVENTREE_SECRET_KEY=abcdefghijklm
- DATABASE_PORT=5432
- DATABASE_HOST=db
restart: unless-stopped |
|
I used this to create a Docker image of InvenTree, but I made some changes:
But as a starting point this worked out great! Thanks! |
Good, I'm glad you found it useful. I'm hoping this can be the basis of a standard docker container you can just pull from docker hub upon every new release of inventree. Everything is configured by variables. Secrets should have the option of specifying files so docker-compose can load in secrets through files that are added inside the container. So production secrets are different than developer secrets. |
|
Hi @rcludwick I've been able to give this some more attention now. Background: I've never used docker before, so I've had to do some reading into how it all fits together. I did not realize dockerhub was a "thing" - but having official InvenTree releases pushed there looks like a cool option! I have some docker related questions which I'm hoping you can answer for me: imageIn your example compose file above, you have the line: Does this try to grab an inventree image from dockerhub? And then "extend" upon it? CustomizationIf the user wishes to use a different database backend, I'm assuming they can simply override the VariablesI note in your compose file you have to put the database username / password in twice. Is it possible to define some variables in the file which can then be re-used? |
|
So currently this builds the docker image from the local inventree git repo. It then saves it in my local docker container cache. So inventree:latest pulls from there, and it always pulls the latest image. In deploying inventree to docker hub, the CICD system would build the docker container using the Dockerfile, then publish it to dockerhub. This would probably happen on a release tag pushed to github. And the Dockerfile can either use the git repo or just pip install from a published package on PyPI say, depending upon how you want to do releases. Then I as a user can just deploy using inventree/inventree:latest say, when I feel like upgrading it by doing a "docker pull" I have about 20 docker containers running on an old laptop, and when I did a OS upgrade, it was the easiest migration I ever did, because docker-compose downloaded all the images and started them up. |
|
That makes sense, thanks Rob. In your example dockerfile you have it setup to run a gunicorn server. I'm assuming it would be possible to configure the dockerfile to use a different webserver if the users require? |
|
Yes. I would just use gunicorn or uwsgi with nginx in reverse proxy, and it's ready to be deployed to production... Or you scale up to two docker containers and then run your own load balancer in front of them. In my case I have 20 docker containers using traefik to proxy them routing by domain name. "grafana.example.com" goes to grafana, "i.example.com" goes to inventree.... etc. So Traefik -> nginx -> gunicorn works just fine. As would an F5 load balancer -> nginx -> gunicorn. |
|
Thank you both rcludwick and SchrodingersGat for looking into providing a Docker image for Inventree. I recently joined a start-up and Inventree looks nearly perfect for our inventory needs, but I'm trying to stick to Docker apps due to their ease in maintenance and app-isolation. I'd definitely throw my vote towards adding InvenTree to the docker hub! rcludwick, two questions if you don't mind:
|
|
I am actually focusing on improving deployment methods for the next major release. This will involve a complete overhaul of the docs, with a focus on robust deployment, rather than simple "getting started" instructions. Inventree is a popular enough project now to warrant this. Also I'll be looking at providing a docker image (or a set of images) with examples of compose files. Regarding the logo bug - this has been fixed in latest master. |
To be fair it's just a Dockerfile that needs to be built to build a local docker image (which serves my purpose)
It requires a git clone to a local directory. Then you can docker build it, so you have to maintain that version yourself.
Yes, I believe that's true. I believe the reason for that is there needs to be an nginx frontend to serve the media directories without auth. Currently I'm using the django static files server and that in order for the media to show up on the login page, you have to auth first (because of the auth middleware, don't you know) @SchrodingersGat I haven't seen how you fixed it, but for docker we're going to want to keep the static media requests from going down into django. This will allow the performance to increase dramatically for larger assets. The next step is to add nginx to the install for the Dockerfile as well as in a supervisord.conf file so that the gunicorn workers, nginx.conf, and the new django q workers all get started at once. @SchrodingersGat has started on supervisord.conf. I can probably find an nginx.conf template to use and modify the Dockerfile. |
|
@rcludwick I think I'm done now :) The official InvenTree docker image is here - https://hub.docker.com/r/inventree/inventree And instructions on how to use it with a compose file: https://inventree.readthedocs.io/en/latest/start/docker/ I've got the docker containers working seamlessly now! Thank you so much for all your help getting this up and running. I'm very happy that InvenTree has a robust dockerized setup process now! Let me know if you see any issues |
|
Congratulations. So one thing you can do now, is it should be pretty easy to set up development for everyone. You can mount your source code in a volume in the docker container where gunicorn runs it, and you can test it out directly. I'm going to switch my "production" server over tomorrow. I'll let you know what I think then. |
|
Just installed Inventree using the docker documentation and it worked perfectly. One additional question. Watchtower is commonly used to update docker images. I'm assuming that to update Inventree you can let watchtower run, and then (depending on whether it's required for the specific release) run the following command afterwards:
Is that correct? |
|
I've never used watchtower, but it shouldn't be any different than any other docker container. Particularly now that inventree exists in dockerhub. |
|
@miniPCR-Jesse sounds about right. You should only have to run |

This builds the mariadb and psycopg2 drivers, as well as install all the software needed to run inventree in a container.
One can build from a forked repo and a custom branch as well.
/usr/src/app is the root directory of the Inventree git repo. This can be mounted as a volume with your local git repo for development.