Docker based production installation

Prerequisites:

  • Docker
  • docker-compose
  • List of sites and server ip added to DNS

1. Install docker-compose-letsencrypt-nginx-proxy-companion

cd $HOME
git clone https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion
cd docker-compose-letsencrypt-nginx-proxy-companion
cp .env.sample .env
./start.sh

2. Clone repository

cd $HOME
git clone https://gitlab.com/castlecraft/erpnext_kubernetes.git
cd erpnext_kubernetes
touch .env

3. Setup .env file

  • MYSQL_ROOT_PASSWORD=admin, set mariadb root password (bootstraps a mariadb container with this root password)
  • SITES=site1.domain.com,site2.domain.com these are list of sites that are part of the bench. Comma (,) separated
  • LETSENCRYPT_EMAIL=your.email@your.domain.com email to for letsencrypt expiry notification

Note: To add more sites recreate erpnext-assets container with sites appended to SITES ENV variable

4. Uncomment following lines from docker/docker-compose-${VERSION}.yml

...

networks:
  default:
    external:
      name: webproxy

5. Comment the exposed port 80:80 from docker/docker-compose-${VERSION}.yml from erpnext-assets service

...
#   ports:
#     - "80:80"

6. Start services (replace appropriate version)

DNS needs to be configured for following to work

docker-compose \
    --project-name erpnext_kubernetes \
    -f docker/docker-compose-$VERSION.yml \
    --project-directory . up -d

7. create new site(s)

# Create ERPNext site
docker exec \
    -e "SITE_NAME=site1.domain.com" \
    -e "INSTALL_ERPNEXT=1" \
    -it erpnext_kubernetes_erpnext-python_1 docker-entrypoint.sh new

# Create Frappe only site
docker exec \
    -e "SITE_NAME=site2.domain.com" \
    -it erpnext_kubernetes_erpnext-python_1 docker-entrypoint.sh new

Wait for mariadb to start. If new site creation fails re-try again after mariadb container is up

8. Update sites

cd $HOME/erpnext_kubernetes

# Pull new images
docker-compose -f docker/docker-compose-$VERSION.yml pull

# Restart containers
docker-compose \
    --project-name erpnext_kubernetes \
    -f docker/docker-compose-$VERSION.yml \
    --project-directory . restart

docker exec \
    -e "MAINTENANCE_MODE=1" \
    -it erpnext_kubernetes_erpnext-python_1 docker-entrypoint.sh migrate

If migrate fails because of redis cache related error remove the redis container(s) and volume(s) and migrate again

docker-compose \
    --project-name erpnext_kubernetes \
    -f docker/docker-compose-$VERSION.yml \
    --project-directory . stop

docker-compose \
    -f docker/docker-compose-$VERSION.yml \
    --project-directory . rm redis-cache redis-queue redis-socketio

docker volume rm \
    erpnext_kubernetes_redis-cache-vol \
    erpnext_kubernetes_redis-queue-vol \
    erpnext_kubernetes_redis-socketio-vol

docker-compose \
    --project-name erpnext_kubernetes \
    -f docker/docker-compose-$VERSION.yml \
    --project-directory . up -d

Read more:

14 Likes

./start should be ./start.sh, right?

2 Likes

Fixed

1 Like

@revant_one could you please add instructions on how to restore a backup?

Would it also be possible to use an external database like AWS RDS?

1 Like

nothing special in container to restore backups.
Manually extract the user uploaded files in appropriate volumes or paths
Manually restore or create database with credentials from site_config.json
For restoring multiple dbs across servers, rsync seems faster.

rsync -avz /var/lib/mysql/* user@example.com:/var/lib/mysql/ 

# at destination as root
chown mysql:mysql -R /var/lib/mysql/

I have success with using separate server under private network (Not Amazon RDS).

Instead of starting the mariadb service, pass your own db_host as environment variable MARIADB_HOST to erpnext-python container. It will create the config with the passed db_host. Other needed config can be changed manually as it will be available in sites directory on host

Related wiki : Using Frappe with Amazon RDS (or any other DBaaS) · frappe/frappe Wiki · GitHub

3 Likes

Hello revant_one,

did you have a solution to use your Docker Container with an external Database?

https://hub.docker.com/_/mariadb

Did we get a ERPNextofficial/ERPNext Container on https://hub.docker.com ?

Wher can i find yout Dockerfile?

one is one, first

Thanks

jannis

Yes

No

Dockerfile(s) for edge images built from develop branch

git repo: castlecraft / erpnext_kubernetes · GitLab

Hello, i’m confused, which ERPNext i the Master Branch, v11 oder v12 at this time?

jannis

There is only master branch

3 directories,
each directory will have Dockerfile. i.e. 3 Dockerfiles
plain Dockerfile is for develop branch.
there is also v11.Dockerfile and v12.Dockerfile

Read docker-entrypoint.sh(s) and Dockerfile(s) to know more

  • erpnext-python image is ERPNext Python environment. Start 5x containers out of it viz. gunicorn, worker-default, worker-short,worker-long,scheduler`. sites/assets directory in gunicorn container is populated by erpnext-assets container.
  • erpnext-assets image serves pre-built assets and populates assets for gunicorn serving jinja
  • frappe-socketio image is the express, socketio server that is needed for websocket
1 Like

Hello @revant_one,

why did you use two reporitory provider https://gitlab.com/ and " https://gitlab.com/" ?

I have try to replicate your How To without success.

Many steps are not clear for me.

jannis

Which two repositories? It is one repository on gitlab.

If you are talking about image registry, it is using docker hub to publish images

You have to understand docker and components.

https://github.com/evertramos/docker-compose-letsencrypt-nginx-proxy-companion is used to serve sites in production. Check their readme and know more. If you don’t know docker, readme will only confuse you more.

  • Understand errors and debug on your own. I generally do that in any FOSS project.
  • Or post the errors and wait for someone to read and solve them (do care to format the error dump). Don’t expect any priority reply in any FOSS projects even if it is contribution.
  • Or best solution will be contact any service provider who understands docker. https://erpnext.org/service-providers (castlecraft.in listed there is my team)
1 Like

Hello, thank you,

i mean “https://gitlab.com” and “https://github.com”.

gitlab and github

jannis