# Docker compose recipe for a production-ready InvenTree setup, with the following containers: # - PostgreSQL as the database backend # - gunicorn as the InvenTree web server # - django-q as the InvenTree background worker process # - nginx as a reverse proxy # - redis as the cache manager (optional, disabled by default)
# --------------------- # READ BEFORE STARTING! # ---------------------
# ----------------------------- # Setting environment variables # ----------------------------- # Shared environment variables should be stored in the env.txt file # Changes made to this file are reflected across all containers! # # IMPORTANT NOTE: # You should not have to change *anything* within this docker-compose.yml file! # Instead, make any changes in the env.txt file!
# ------------------------ # InvenTree Image Versions # ------------------------ # By default, this docker-compose script targets the STABLE version of InvenTree, # image: inventree/inventree:stable # # To run the LATEST (development) version of InvenTree, # change the INVENTREE_TAG variable (in the env.txt file) to "latest" # # Alternatively, you could target a specific tagged release version with (for example): # INVENTREE_TAG=0.7.5 #
services: # Database service # Use PostgreSQL as the database backend inventree-db: image:postgres:13 container_name:inventree-db expose: -${INVENTREE_DB_PORT:-5432}/tcp environment: -PGDATA=/var/lib/postgresql/data/pgdb -POSTGRES_USER=${INVENTREE_DB_USER:?Youmustprovidethe'INVENTREE_DB_USER'variableintheenv.txtfile} -POSTGRES_PASSWORD=${INVENTREE_DB_PASSWORD:?Youmustprovidethe'INVENTREE_DB_PASSWORD'variableintheenv.txtfile} -POSTGRES_DB=${INVENTREE_DB_NAME:?Youmustprovidethe'INVENTREE_DB_NAME'variableintheenv.txtfile} volumes: # Map 'data' volume such that postgres database is stored externally -inventree_data:/var/lib/postgresql/data/ restart:unless-stopped
# redis acts as database cache manager # only runs under the "redis" profile : https://docs.docker.com/compose/profiles/ inventree-cache: image:redis:7.0 container_name:inventree-cache depends_on: -inventree-db profiles: -redis env_file: -.env expose: -${INVENTREE_CACHE_PORT:-6379} restart:always
# InvenTree web server service # Uses gunicorn as the web server inventree-server: # If you wish to specify a particular InvenTree version, do so here image:inventree/inventree:${INVENTREE_TAG:-stable} container_name:inventree-server # Only change this port if you understand the stack. # If you change this you have to change: # - the proxy settings (on two lines) # - only change the exposed port - eg `1338:8000` if you want to expose the server on port 1338 expose: -8000 depends_on: -inventree-db env_file: -.env volumes: # Data volume must map to /home/inventree/data -inventree_data:/home/inventree/data restart:unless-stopped
# Background worker process handles long-running or periodic tasks inventree-worker: # If you wish to specify a particular InvenTree version, do so here image:inventree/inventree:${INVENTREE_TAG:-stable} container_name:inventree-worker command:invokeworker depends_on: -inventree-server env_file: -.env volumes: # Data volume must map to /home/inventree/data -inventree_data:/home/inventree/data restart:unless-stopped
# nginx acts as a reverse proxy # static files are served directly by nginx # media files are served by nginx, although authentication is redirected to inventree-server # web requests are redirected to gunicorn # NOTE: You will need to provide a working nginx.conf file! inventree-proxy: image:nginx container_name:inventree-proxy depends_on: -inventree-server env_file: -.env ports: # Default web port is 1337 (can be changed in the env.txt file) -${INVENTREE_WEB_PORT:-1337}:80 volumes: # Provide nginx configuration file to the container # Refer to the provided example file as a starting point -./nginx.prod.conf:/etc/nginx/conf.d/default.conf:ro # nginx proxy needs access to static and media files -inventree_data:/var/www restart:unless-stopped
volumes: # Persistent data, stored external to the container(s) inventree_data: driver:local driver_opts: type:none o:bind # This directory specified where InvenTree data are stored "outside" the docker containers device:${INVENTREE_EXT_VOLUME:?Youmustspecifythe'INVENTREE_EXT_VOLUME'variableintheenv.txtfile!}
# Listen for connection on (internal) port 80 # If you are exposing this server to the internet, you should use HTTPS! # In which case, you should also set up a redirect from HTTP to HTTPS, and listen on port 443 # See the Nginx documentation for more details listen80;
# InvenTree environment variables for a postgresql production setup
# Location of persistent database data (stored external to the docker containers) # Note: You *must* un-comment this line, and point it to a path on your local machine
# e.g. Linux INVENTREE_EXT_VOLUME=/volume1/docker/inventree/data
# e.g. Windows (docker desktop) #INVENTREE_EXT_VOLUME=c:/Users/me/inventree-data
# Default web port for the InvenTree server INVENTREE_WEB_PORT=1337
# Ensure debug is false for a production setup INVENTREE_DEBUG=False INVENTREE_LOG_LEVEL=WARNING
# InvenTree admin account details # Un-comment (and complete) these lines to auto-create an admin acount INVENTREE_ADMIN_USER=laosu INVENTREE_ADMIN_PASSWORD=123456 INVENTREE_ADMIN_EMAIL=wbsu2003@gmail.com
# Database configuration options # Note: The example setup is for a PostgreSQL database INVENTREE_DB_ENGINE=postgresql INVENTREE_DB_NAME=inventree INVENTREE_DB_HOST=inventree-db INVENTREE_DB_PORT=5432
# Database credentials - These must be configured before running # Uncomment the lines below, and change from the default values! INVENTREE_DB_USER=pguser INVENTREE_DB_PASSWORD=pgpassword
# Redis cache setup (disabled by default) # Un-comment the following lines to enable Redis cache # Note that you will also have to run docker-compose with the --profile redis command # Refer to settings.py for other cache options #INVENTREE_CACHE_HOST=inventree-cache #INVENTREE_CACHE_PORT=6379
# Options for gunicorn server INVENTREE_GUNICORN_TIMEOUT=90
Server Restart Required A configuration option has been changed which requires a server restart. Contact your system administrator for further information
其他
一些其他可能会用到的命令
1 2 3 4 5 6 7 8
# 一键删除 docker-compose down
# 将数据库导出为 JSON docker-compose run inventree-server invoke export-records -f /volume1/docker/inventree/data/data.json