diff --git a/_includes/nginx.conf b/_includes/nginx.conf index af681b0..1688c1e 100644 --- a/_includes/nginx.conf +++ b/_includes/nginx.conf @@ -1,6 +1,6 @@ upstream inventree { # Should point to the InvenTree web server container - server web:8000; + server inventree:8000; } server { diff --git a/docs/start/docker.md b/docs/start/docker.md index a016551..1ee6928 100644 --- a/docs/start/docker.md +++ b/docs/start/docker.md @@ -4,12 +4,67 @@ title: Docker Setup ## Docker Image -The most convenient method of installing and running InvenTree is to use the official [docker image](https://hub.docker.com/r/inventree/inventree). +The most convenient method of installing and running InvenTree is to use the official [docker image](https://hub.docker.com/r/inventree/inventree), available from docker-hub. -The InvenTree docker image contains all the required system packages, python modules, and configuration files for running InvenTree. +The InvenTree docker image contains all the required system packages, python modules, and configuration files for running a containerised InvenTree web server. -!!! info "Configuration Files" - All of the configuration files discussed below are available under the *docker* subdirectory of the [InvenTree source code](https://github.com/inventree/inventree) +### Environment Variables + +InvenTree run-time configuration options described in the [configuration documentation](../config) can be passed to the InvenTree container as environment variables. + +Additionally, the following environment variables are used to control functionality specific to the docker container: + +| Variable | Description | Default | +| --- | --- | --- | +| INVENTREE_WEB_PORT | Internal container port on which the InvenTree web server is hosted | 8000 | + +The following environment variables for InvenTree server configuration are specified as part of the docker image, and can be overridden if required: + +| Variable | Value | +| --- | --- | +| INVENTREE_LOG_LEVEL | INFO | +| INVENTREE_CONFIG_FILE | /home/inventree/data/config.yaml | +| INVENTREE_SECRET_KEY_FILE | /home/inventree/data/secret_key.txt | +| INVENTREE_DB_ENGINE | postgresql | +| INVENTREE_DB_NAME | inventree | +| INVENTREE_DB_HOST | db | +| INVENTREE_DB_PORT | 5432 | + +The following environment variables are explicitly **not configured** and must be passed to the container instance: + +- INVENTREE_DB_USER +- INVENTREE_DB_PASSWORD + +### Data Directory + +Persistent data (e.g. uploaded media files) should be stored outside the container instance. + +InvenTree data are stored inside the container at `/home/inventree/data`. + +This directory should be mounted as a volume which points to a directory on your local machine. + +### Static Directory + +Static files are stored internal to the container instance, at the location `/home/inventree/static` + +### Configuration File + +As discussed in the [configuration documentation](../config), InvenTree run-time settings can be provided in a configuration file. + +By default, the docker container expects this configuration file in the location `/home/inventree/data/config.yaml`. If this file does not exist, it will be automatically created from a default template file. + +As this config file is inside the "data" directory (which should be mounted as a volume) it can be edited outside the context of the container, if necessary. + +### Secret Key + +InvenTree uses a secret key to provide cryptographic signing for the application. + +As specified in the [configuration documentation](../config/#secret-key) this can be passed to the InvenTree application directly as an environment variable, or provided via a file. + +By default, the InvenTree container expects the `INVENTREE_SECRET_KEY_FILE` to exist at `/home/inventree/data/secret_key.txt`. If this file does not exist, it will be created and a new key will be randomly generated. + +!!! warning "Same Key" + Each InvenTree container instance must use the same secret key value, otherwise unexpected behavior will occur. ## Docker Compose @@ -70,27 +125,18 @@ InvenTree stores data which is meant to be persistent (e.g. uploaded media files Static files are shared between multiple containers (but not exposed to the local file system). -## Environment Variables +## Production Setup -The InvenTree web server requires a number of configuration options to be specified to connect to the database. These are provided to the docker container(s) using the `environment:` section for each container +With the docker-compose recipe above, follow the instructions below to initialize a complete production server for InvenTree. -In the default configuration, only the following environment variables are required for the `web` and `worker` containers: +### Required Files -- **INVENTREE_DB_USER** - Database username (default=pguser) -- **INVENTREE_DB_PASSWORD** - Database password (default=pgpassword) +The following files are required on your local machine (use the examples above, or edit as required): -!!! warning "Altering Database Configuration" - If the database image is altered from the default postgresql image, then the InvenTree environment variables must be adjusted to match. +- docker-compose.yml +- nginx.conf -### Docker Compose File - -Use the following docker-compose file as a starting point: - -## Initial Setup Process - -Follow the instructions below to initialize a complete docker deployment for InvenTree. - -!!! info "Directory" +!!! info "Command Directory" It is assumed that all commands will be run from the directory where `docker-compose.yml` is located. ### Configure Compose File @@ -99,7 +145,10 @@ Save and edit the `docker-compose.yml` file as required. The only **required** change is to ensure that the `/path/to/data` entry (at the end of the file) points to the correct directory on your local file system, where you want InvenTree data to be stored. -### Launch Database Server +!!! info "Database Credentials" + You may also wish to change the default postgresql username and password! + +### Launch Database Container Before we can create the database, we need to launch the database server container: @@ -111,6 +160,8 @@ This starts the database container. ### Create Database +As this is the first time we are interacting with the docker containers, the InvenTree database has not yet been created. + Run the following command to open a shell session for the database: ``` @@ -122,7 +173,7 @@ docker-compose run inventree pgcli -h db -p 5432 -u pguser You will be prompted to enter the database user password (default="pgpassword", unless altered in the compose file). -Next, run the following command in the database shell: +Once logged in, run the following command in the database shell: ``` create database inventree; @@ -132,7 +183,7 @@ Then exit the shell with Ctrl+d ### Perform Database Migrations -The database has been created, but it is empty! We need to perform the initial database migrations. +The database has now been created, but it is empty! We need to perform the initial database migrations: ``` docker-compose run inventree invoke migrate @@ -191,14 +242,34 @@ This command launches the remaining container processes: !!! success "Up and Running!" You should now be able to view the InvenTree login screen at [http://localhost:1337](http://localhost:1337) -## Database Access - -## Production Serevr - -## Development Server - ## Updating InvenTree -## SEcret Key +To update your InvenTree installation to the latest version, follow these steps: -## Settings file \ No newline at end of file +### Stop Containers + +Stop all running containers as below: + +``` +docker-compose down +``` + +### Update Images + +Pull down the latest version of the InvenTree docker image + +``` +docker-compose pull +``` + +This ensures that the InvenTree containers will be running the latest version of the InvenTree source code. + +### Start Containers + +Now restart the containers. + +As part of the server initialization process, data migrations and static file updates will be performed automatically. + +``` +docker-compose up -d +``` \ No newline at end of file