PromucFlow_constructor/deploy/docker
Goutham Pratapa 1de045d9d8
chore: Add dependency to start backend only if rts is ready (#19218)
Fixes: [19207](https://github.com/appsmithorg/appsmith/issues/19207)

**By default on start-up**

```
root@ab348246fff8:/appsmith-stacks/logs# head backend/backend-ab348246fff8.log
Waiting for RTS to start ...
RTS started.
Starting Backend server...
Load environment configuration
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/appsmith/backend/server.jar!/BOOT-INF/lib/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/appsmith/backend/server.jar!/BOOT-INF/lib/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
[2022-12-26 11:39:34,962]  - Starting ServerApplication vv1.8.14.1 using Java 11.0.17 on ab348246fff8 with PID 1543 (/opt/appsmith/backend/server.jar started by root in /opt/appsmith/backend)
```
**Upon stopping RTS manually** 

```
root@ab348246fff8:/appsmith-stacks/logs# supervisorctl stop rts
rts: stopped
root@ab348246fff8:/appsmith-stacks/logs# supervisorctl status
backend                          RUNNING   pid 1497, uptime 0:01:21
cron                             RUNNING   pid 1505, uptime 0:01:21
editor                           RUNNING   pid 1502, uptime 0:01:21
mongodb                          RUNNING   pid 1491, uptime 0:01:21
redis                            RUNNING   pid 1490, uptime 0:01:21
rts                              STOPPED   Dec 26 11:40 AM
stdout                           RUNNING   pid 1489, uptime 0:01:21
```

**Restart Backend service to check if backend service starts** 

```
root@ab348246fff8:/appsmith-stacks/logs# supervisorctl restart backend
backend: stopped
backend: started
root@ab348246fff8:/appsmith-stacks/logs# supervisorctl status
backend                          RUNNING   pid 1802, uptime 0:00:12
cron                             RUNNING   pid 1505, uptime 0:01:43
editor                           RUNNING   pid 1502, uptime 0:01:43
mongodb                          RUNNING   pid 1491, uptime 0:01:43
redis                            RUNNING   pid 1490, uptime 0:01:43
rts                              STOPPED   Dec 26 11:40 AM
stdout                           RUNNING   pid 1489, uptime 0:01:43
root@ab348246fff8:/appsmith-stacks/logs# supervisorctl ^C
root@ab348246fff8:/appsmith-stacks/logs# tail -f backend/backend-ab348246fff8.log
Waiting for RTS to start ...
Waiting for RTS to start ...
Waiting for RTS to start ...
Waiting for RTS to start ...
Waiting for RTS to start ...
Waiting for RTS to start ...
Waiting for RTS to start ...
Waiting for RTS to start ...
Waiting for RTS to start ...
Waiting for RTS to start ...
^C
```

**Upon starting RTS the behaviour of backend immediately**
 
```
root@ab348246fff8:/appsmith-stacks/logs# supervisorctl start rts
rts: started
root@ab348246fff8:/appsmith-stacks/logs# tail -f backend/backend-ab348246fff8.log
Starting Backend server...
Load environment configuration
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/appsmith/backend/server.jar!/BOOT-INF/lib/logback-classic-1.2.11.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/appsmith/backend/server.jar!/BOOT-INF/lib/slf4j-reload4j-1.7.36.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [ch.qos.logback.classic.util.ContextSelectorStaticBinder]
[2022-12-26 11:41:33,796]  - Starting ServerApplication vv1.8.14.1 using Java 11.0.17 on ab348246fff8 with PID 1968 (/opt/appsmith/backend/server.jar started by root in /opt/appsmith/backend)
[2022-12-26 11:41:33,799]  - Running with Spring Boot v2.6.5, Spring v5.3.17
[2022-12-26 11:41:33,803]  - No active profile set, falling back to 1 default profile: "default"
[2022-12-26 11:41:34,615]  - Multiple Spring Data modules found, entering strict repository configuration mode!
[2022-12-26 11:41:34,616]  - Bootstrapping Spring Data Reactive MongoDB repositories in DEFAULT mode.
[2022-12-26 11:41:34,859]  - Finished Spring Data repository scanning in 239 ms. Found 55 Reactive MongoDB repository interfaces.
[2022-12-26 11:41:35,220]  - Multiple Spring Data modules found, entering strict repository configuration mode!
[2022-12-26 11:41:35,221]  - Bootstrapping Spring Data Redis repositories in DEFAULT mode.
```
2022-12-29 14:22:41 +05:30
..
images docs: Fat container documentation fixes (#7207) 2021-09-14 19:01:06 +05:30
scripts Sandboxed iFrames with srcDoc (#11426) 2022-10-04 15:20:45 +05:30
templates chore: Add dependency to start backend only if rts is ready (#19218) 2022-12-29 14:22:41 +05:30
utils chore: bump minimatch from 3.0.4 to 3.1.2 in /deploy/docker/utils (#18344) 2022-11-26 12:23:33 +05:30
watchtower-hooks Auto-backup and cleanup with appsmithctl (#15203) 2022-07-28 17:45:28 +05:30
.gitignore docs: Fat container documentation fixes (#7207) 2021-09-14 19:01:06 +05:30
build-multi-arch.md feat: Support building Docker image for ARM arch (#7832) 2021-09-29 14:33:27 +05:30
build-mutil-arch.sh feat: Support building Docker image for ARM arch (#7832) 2021-09-29 14:33:27 +05:30
docker-compose.yml Packer script to build AWS and DigitalOcean images (#16617) 2022-09-14 11:03:02 +05:30
entrypoint.sh chore: Add role details in replica set error message (#18472) 2022-11-27 13:46:05 +05:30
README.md Disable auto updates helm and docker-compose doc (#13443) 2022-04-29 17:16:37 +05:30
run-test.sh Fix fat image not being pushed to DockerHub 2021-12-17 06:42:17 +05:30

Appsmith Docker Image

The Appsmith Docker image is built with all the components required for it to run, within a single Docker container. Files in this directory make up for the scripts and template files needed for building the image.

You may choose to use the Appsmith cloud instance (at app.appsmith.com) or start your own using this image.

Appsmith Cloud

The fastest way to get started with appsmith is using our cloud-hosted version. It's as easy as

  1. Create an Account
  2. Docs on Building a UI

Self Host

The following subsections describe how you can get started with your own instance of Appsmith.

1. Prerequisites

Ensure docker and docker-compose are installed and available for starting containers:

You may verify the installation by running docker --version and docker-compose --version. The output should roughly be something like below:

$ docker --version
Docker version 20.10.7, build f0df350
$ docker-compose --version
docker-compose version 1.29.2, build 5becea4c

2. Docker compose configuration

Create a folder called appsmith (or some other name that you like), which will serve as our installation folder. Inside this folder, create a docker-compose.yml file and copy the following content into it:

version: "3"

services:
  appsmith:
    image: appsmith/appsmith-ce
    container_name: appsmith-ce
    ports:
      - "80:80"
      - "443:443"
      - "9001:9001"
    volumes:
      - ./stacks:/appsmith-stacks
    restart: unless-stopped
  #   # Uncomment the lines below to enable auto-update
  #   labels:
  #     com.centurylinklabs.watchtower.enable: "true"

  # auto_update:
  #   image: containrrr/watchtower:latest-dev
  #   volumes:
  #     - /var/run/docker.sock:/var/run/docker.sock
  #   # Update check interval in seconds.
  #   command: --schedule "0 0 * ? * *" --label-enable --cleanup
  #   restart: unless-stopped


Note: To enable auto-update for Appsmith, please uncomment all the commented lines in the docker-compose file.

After saving this file, cd to the folder that contains this file and run the following command to start Appsmith:

docker-compose up -d

This command may take a few minutes to download the docker image and initialize the application. Appsmith should soon be available at http://localhost.

You can check if application is running correctly by running docker ps or docker-compose ps (running docker-compose will require you to be in the directory containing the docker-compose.yml file to work).

$ docker ps
CONTAINER ID        IMAGE                             COMMAND                  CREATED             STATUS              PORTS                                      NAMES
3b8f2c9638d0        appsmith/appsmith          "/opt/appsmith/entrypoint.sh"   17 minutes ago      Up 17 minutes       0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp   appsmith

You can also use the Supervisord UI to monitor and manage the different processes inside the container. This is discussed further below.

Custom Domain

To make Appsmith available on a custom domain, please update your domain's DNS records to point to the instance running Appsmith. Most domain registrars / DNS-providers have documentation on how you can do this yourself.

Custom SSL Certificate

In our container, we support to generate a free SSL certificate If you have your owned certificate, please follow these steps to use it inside the container.

  • Firstly, please rename your certificate file as fullchain.pem and key file as privkey.pem
  • Then, copy these files into the sub-directory <mounting-directory>/ssl/ (Note: Please change <mounting-directory> by the mounting volume directory in the docker-compose.yml. Default is ./stacks)
  • Restart the container using docker restart appsmith

The container will check the certificate files in the folder <mounting-directory>/ssl and use them if they are existed.

Note: In case of the certificate files have different name from fullchain.pem and privkey.pem, it will be considered as missing custom certificate and auto-provisioning the certificate by Let's Encrypt

Instance Management Utilities

The image includes an appsmithctl command to help with the management and maintenance of your instance. The following subsections describe what's available.

Export database

The following command can be used to take a backup dump of Appsmith's database. This can be restored onto another instance using the import command (discussed below) to restore all data.

Before running this, ensure you are in the directory where docker-compose.yml is located.

docker-compose exec appsmith-ce appsmithctl export_db

The output file will be stored in the container directory /appsmith-stacks/data/backup/appsmith-data.archive. Thanks to the volume configuration in the docker-compose.yml file, it should be available on your host machine at ./stacks/data/backup/appsmith-data.archive.

If your volume configuration is different or unavailable, you can use the following command to copy the archive file to your host disk:

docker-compose cp appsmith-ce:/appsmith-stacks/data/backup/appsmith-data.archive .

Note that you may want to save the docker.env file in addition to this archive file, if you intend to be able to reproduce this environment elsewhere, or in case of a disaster. This file can be copied out of the container with the following command:

docker-compose cp appsmith-ce:/appsmith-stacks/configuration/docker.env .

Be sure to keep this file safe, since it contains information that can be used to decrypt datasource information from the database archive.

Import database

The following command can restore backup archive, that was produced by the export command (discussed above).

First, copy the archive file into the container using the following command:

docker-compose cp ./appsmith-data.archive appsmith-ce:/appsmith-stacks/data/restore/

Second, run the following command to import data from this file:

docker-compose exec appsmith-ce appsmithctl import_db

Note that when you restore, you may also want to copy a docker.env from the original instance into this one. You can use the following command to do this (assuming you are in the installation folder and docker.env exists in the same folder):

docker-compose cp ./docker.env appsmith-ce:/appsmith-stacks/configuration/

This will need a restart of the Appsmith server, which can be done using the following command:

docker-compose exec appsmith-ce supervisorctl restart backend

Migrate To New Server

To migrate a running container to a new server or other machine, you can use the following migrate command and replace the <user> and <new-server-ip-address> by the user and IP address of the destination server or machine.

docker exec appsmith-ce appsmithctl migrate <user>@<new-server-ip-address>

This command will migrate all data and configuration of running container on source machine to destination machine and start a new container on destination machine.

Supervisor

The container runs multiple processes, including the Appsmith server, Nginx, MongoDB etc., inside a single Docker container. These processes are started and managed by supervisord.

Supervisord comes with a web interface for managing the various processes, available at http://localhost/supervisor/, as well as a command line interface towards the same goal.

Here's a screenshot of the web interface listing all the processes managed:

The command line interface can also be used to perform operations like restarting the Appsmith server, or restarting Nginx etc. For example, the following command (run in the installation folder) can be used to get a status of all running processes:

docker-compose exec appsmith-ce supervisorctl status

Or to view the last few lines of stderr output of one of the processes:

docker-compose exec appsmith-ce supervisorctl tail backend stderr

To learn more, please refer to Supervisor's documentation on what actions are available to be performed by the command line interface.

Troubleshooting

If you encounter any errors during this process, please reach out to support@appsmith.com or join our Discord Server and reach out on the #support channel.