What you will set up
ERPNext is an open-source ERP: accounting, invoices, customers, suppliers, stock, purchasing, projects and HR, in your browser. It is built on the Frappe framework, and all of it stays on your server.
Here it runs as eight Compose services under a user of its own called erpnext, behind Caddy from the rootless Docker guide: MariaDB, two Redis servers, and ERPNext's web server, background worker, scheduler, realtime server and web front.
The Docker setup follows our tested rootless Docker guide on Debian 13. The app version and the app-specific behaviour below come from the tested Podman guide on a Melonslab server; the Docker steps for this app were not re-tested end to end. In the Podman test, ERPNext used about 710 MB of memory with one company and few users. For a company in Sweden, the setup wizard chose SEK and the Swedish BAS 2024 chart of accounts, a customer, an item and an invoice were created, the invoice was downloaded as a PDF, logins showed each visitor's real address, and an update and a reboot were checked. The ERPNext project recommends 2 vCPU and 4 GB for a server running it.
Before you start
You need:
- a server set up as in the rootless Docker guide, with Caddy running, and at least 4 GB of memory;
- an A record and an AAAA record for
erp.example.compointing at your server.
The examples use erp.example.com for ERPNext and 203.0.113.10 for your server's IPv4 address, which ip -brief address show eth0 shows. Replace them throughout.
1. Create the user
As root:
useradd -m -s /bin/bash -U erpnext
loginctl enable-linger erpnext
mkdir -p /home/erpnext/erpnext/{db,redis-queue,sites,backup}
chown -R erpnext:erpnext /home/erpnext/erpnext
Do not add the user to the docker group. The daemon is rootless and belongs to this user.
2. Create the database password
As root, generate MariaDB's root password and put it in a 0600 file:
umask 077
printf 'MARIADB_ROOT_PASSWORD=%s\n' "$(openssl rand -hex 24)" > /home/erpnext/erpnext/db.env
chown erpnext:erpnext /home/erpnext/erpnext/db.env
chmod 600 /home/erpnext/erpnext/db.env
ERPNext uses it once, in step 6, to create its own database and database user. Compose passes the file in as an environment variable through env_file.
3. Define the Compose services
Create /home/erpnext/erpnext/compose.yaml:
cat > /home/erpnext/erpnext/compose.yaml <<'YAML'
x-erpnext: &erpnext
image: docker.io/frappe/erpnext:v16.36.0
volumes:
- ./sites:/home/frappe/frappe-bench/sites
restart: always
services:
db:
image: docker.io/library/mariadb:11.8
env_file: db.env
environment:
MARIADB_AUTO_UPGRADE: "1"
command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci --skip-character-set-client-handshake
volumes:
- ./db:/var/lib/mysql
restart: always
redis-cache:
image: docker.io/library/redis:8.6-alpine
restart: always
redis-queue:
image: docker.io/library/redis:8.6-alpine
command: redis-server --port 6380
volumes:
- ./redis-queue:/data
restart: always
backend:
<<: *erpnext
# ERPNext fetches its own pages when it makes PDFs: reach them through the host.
extra_hosts:
- "erp.example.com:host-gateway"
depends_on:
- db
- redis-cache
- redis-queue
worker:
<<: *erpnext
command: bench worker --queue long,default,short
depends_on:
- backend
scheduler:
<<: *erpnext
command: bench schedule
depends_on:
- backend
websocket:
<<: *erpnext
command: node /home/frappe/frappe-bench/apps/frappe/socketio.js
depends_on:
- backend
frontend:
<<: *erpnext
command: nginx-entrypoint.sh
environment:
BACKEND: backend:8000
SOCKETIO: websocket:9000
UPSTREAM_REAL_IP_ADDRESS: "203.0.113.10"
ports:
# Only Caddy, on this server, can reach ERPNext: the port is not open to the internet.
- "127.0.0.1:8093:8080"
depends_on:
- backend
- websocket
YAML
The five ERPNext services share the same image and the sites directory, where ERPNext keeps its settings and uploaded files. The YAML anchor in x-erpnext just repeats those shared settings; Compose ignores the x- key as a service. On the Compose network the services reach each other by name, and the second Redis listens on port 6380. The ERPNext image is pinned to an exact version, because each update also needs a database step, as step 10 shows.
Start it:
uid=$(id -u erpnext)
runuser -u erpnext -- env HOME=/home/erpnext XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/erpnext/erpnext && docker compose pull && docker compose up -d && docker compose ps"
The first start downloads images that take about 3.4 GB of disk. Once all services are up, go on. Until the next step is done, the worker, scheduler and websocket services keep restarting.
Add the weekly docker-update.service and docker-update.timer from the rootless Docker guide, with WorkingDirectory=/home/erpnext/erpnext, and enable the timer as erpnext. It pulls new images and recreates the services; ERPNext's own version is changed as in step 10.
4. Tell ERPNext where everything is
uid=$(id -u erpnext)
runuser -u erpnext -- env HOME=/home/erpnext XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/erpnext/erpnext && docker compose exec -T backend bash -c 'bench set-config -g db_host db && bench set-config -gp db_port 3306 && bench set-config -g redis_cache redis://redis-cache:6379 && bench set-config -g redis_queue redis://redis-queue:6380 && bench set-config -g redis_socketio redis://redis-queue:6380 && bench set-config -gp socketio_port 9000 && bench set-config -g chromium_path /usr/bin/chromium-headless-shell' && docker compose restart"
That writes the addresses of the database and Redis into common_site_config.json in the sites directory, which every ERPNext service reads. The restart lets the worker, scheduler and websocket settle.
5. Create the site
ERPNext calls each installation a site, named after its address. Print the database password first, since the next command asks for it:
cut -d= -f2- /home/erpnext/erpnext/db.env; echo
uid=$(id -u erpnext)
runuser -u erpnext -- env HOME=/home/erpnext XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/erpnext/erpnext && docker compose exec -it backend bench new-site erp.example.com --mariadb-user-host-login-scope='%' --install-app erpnext --set-default"
It asks three things:
Enter mysql super user [root]:press Enter;MySQL root password:paste the database password;Set Administrator password:choose a password for ERPNext'sAdministratoruser.
Installing took about 12 minutes on 2 vCPU in the Podman test. Then turn on the scheduler, which is off for a new site, and give ERPNext its public address, which it uses in links and emails:
uid=$(id -u erpnext)
runuser -u erpnext -- env HOME=/home/erpnext XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/erpnext/erpnext && docker compose exec -T backend bench --site erp.example.com enable-scheduler && docker compose exec -T backend bench --site erp.example.com set-config host_name https://erp.example.com"
6. Put Caddy in front
As root, add this block at the end of /home/caddy/Caddyfile:
erp.example.com {
reverse_proxy 127.0.0.1:8093
}
chown caddy:caddy /home/caddy/Caddyfile
uid=$(id -u caddy)
runuser -u caddy -- env HOME=/home/caddy XDG_RUNTIME_DIR=/run/user/$uid \
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/$uid/bus PATH=/usr/bin:/bin \
bash -lc "export DOCKER_HOST=unix:///run/user/$uid/docker.sock; cd /home/caddy/caddy && docker compose restart caddy"
7. Run the setup wizard
Open https://erp.example.com, and log in as Administrator with the password from step 5. The setup wizard has four steps:
- Welcome: check Your Language, Your Country, Time Zone and Currency, which ERPNext guesses from where you are.
- Your own account: Full Name, Email Address and Password. From now on, you log in with this email address.
- Four questions about your business, and the modules you plan to use.
- Setup your organization: Company Name, Company Abbreviation, Chart of Accounts and Financial Year Begins On. For a company in Sweden, ERPNext picks BAS 2024 med Nummer, the Swedish standard chart of accounts.
Choose Complete Setup. After about a minute, ERPNext opens its desk, with Accounting, Selling, Buying, Stock and the other modules. Keep the Administrator password for maintenance, and work as your own user.
8. What to do next
Some good first steps, each found by typing its name in the search bar at the top of ERPNext:
- User List: add your colleagues, each with the roles they need;
- Email Account: set up outgoing email, so that invoices can be sent from ERPNext;
- Sales Taxes and Charges Template: check the VAT templates that came with the chart of accounts, such as
Försäljning Moms 25%, with your accountant.
9. Keep it up to date
The weekly timer from step 3 pulls new images of MariaDB and Redis and recreates the services. ERPNext itself is updated by hand, because the database has to be migrated to each new version. New versions of ERPNext 16 come out every week or two, on the GitHub page for ERPNext's releases. Back up first, as in step 10, then, with the new version in place of v16.37.0:
uid=$(id -u erpnext)
runuser -u erpnext -- env HOME=/home/erpnext XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/erpnext/erpnext && sed -i 's|v16.36.0|v16.37.0|g' compose.yaml && docker compose pull && docker compose up -d"
Wait for the services to settle, then run the migration as erpnext:
uid=$(id -u erpnext)
runuser -u erpnext -- env HOME=/home/erpnext XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/erpnext/erpnext && docker compose exec -T backend bench --site all migrate && docker compose exec -T backend bench version"
Pulling before recreating keeps the pause short. A new major version, such as 17, has its own upgrade notes: read them before you change the tag.
10. Back up
As erpnext:
uid=$(id -u erpnext)
runuser -u erpnext -- env HOME=/home/erpnext XDG_RUNTIME_DIR=/run/user/$uid \
DOCKER_HOST=unix:///run/user/$uid/docker.sock PATH=/usr/bin:/bin \
bash -lc "cd /home/erpnext/erpnext && docker compose exec -T backend bench --site all backup --with-files && docker compose cp backend:/home/frappe/frappe-bench/sites/erp.example.com/private/backups/. backup/"
Each backup has four files: the database, the public and the private files, and the site's settings with its encryption key, which is needed to restore saved passwords. Copy /home/erpnext/erpnext/backup to another machine, and keep it private: it holds all your accounts.
Troubleshooting
Downloading a PDF fails, and the error says wkhtmltopdf reported an error with ConnectionRefusedError. The extra_hosts entry in compose.yaml is missing, or names a different host. ERPNext fetches its own address when it makes a PDF.
The worker, scheduler or websocket service keeps restarting. Step 4 has not been done, or the services were not restarted after it.
Scheduled jobs, such as recurring invoices or email, never run. Run the enable-scheduler command from step 5.