跳到主要内容

docker开发环境搭建

镜像克隆到本地

docker pull frappe/bench:latest

用dokcer安装 frappe-bench

Clone frappe_docker

git clone https://github.com/frappe/frappe_docker.git
cd frappe_docker

Install bench using docker

cp -R devcontainer-example bench
docker-compose -f bench/docker-compose.yml up -d

compose文件

version: "3.7"
services:
mariadb:
image: mariadb:10.6
command:
- --character-set-server=utf8mb4
- --collation-server=utf8mb4_unicode_ci
- --skip-character-set-client-handshake
- --skip-innodb-read-only-compressed # Temporary fix for MariaDB 10.6
environment:
MYSQL_ROOT_PASSWORD: 123
volumes:
- mariadb-data:/var/lib/mysql

# Enable PostgreSQL only if you use it, see development/README.md for more information.
# postgresql:
# image: postgres:11.8
# environment:
# POSTGRES_PASSWORD: 123
# volumes:
# - postgresql-data:/var/lib/postgresql/data

redis-cache:
image: redis:alpine

redis-queue:
image: redis:alpine

redis-socketio:
image: redis:alpine

frappe:
image: frappe/bench:latest
command: sleep infinity
environment:
- SHELL=/bin/bash
volumes:
- ..:/workspace:cached
# Enable if you require git cloning
# - ${HOME}/.ssh:/home/frappe/.ssh
working_dir: /workspace/development
ports:
- 8000-8005:8000-8005
- 9000-9005:9000-9005

volumes:
mariadb-data:
postgresql-data:

Exec into the container

docker exec -e "TERM=xterm-256color" -w /workspace/development -it bench_frappe_1 bash

Install Frappe Framework and ERPNext

# Install bench for root
supo pip3 install -e /home/frappe/.bench

# Create frappe-bench
bench init --skip-redis-config-generation --frappe-branch version-12 frappe-bench
cd frappe-bench

# Set docker specific hosts
bench set-mariadb-host mariadb
bench set-redis-cache-host redis-cache:6379
bench set-redis-queue-host redis-queue:6379
bench set-redis-socketio-host redis-socketio:6379

# Get ERPNext
bench get-app --branch version-12 erpnext

# Create new site
bench new-site myerp.mysite.com --mariadb-root-password 123 --admin-password admin --no-mariadb-socket

# Install ERPNext on site
bench --site myerp.mysite.com install-app erpnext

# Setup supervisor (includes nginx)
bench setup supervisor --skip-redis

# Symlink or copy supervisor and nginx configs
sudo ln -s `pwd`/config/nginx.conf /etc/nginx/conf.d/frappe.conf
sudo ln -s `pwd`/config/supervisor.conf /etc/supervisor/conf.d/frappe.conf
# Or copy supervisor and nginx configs
sudo cp `pwd`/config/nginx.conf /etc/nginx/conf.d/frappe.conf
sudo cp `pwd`/config/supervisor.conf /etc/supervisor/conf.d/frappe.conf

# exit container

Start supervisord

docker exec --user root -e "TERM=xterm-256color" -w /workspace/development -d bench_frappe_1 supervisord

Stop supervisord

docker exec --user root -e "TERM=xterm-256color" -w /workspace/development -d bench_frappe_1 supervisorctl stop all

Notes:

  • publish port 80 in bench/docker-compose.yml
  • Add volumes for /etc/nginx/conf.d/ and /etc/supervisor/conf.d/
  • default frappe/bench:latest image does not have supervisor and nginx installed. Either install or build new image with frappe/bench as base image