Note: Before reading this document, make sure you have installed both docker and docker-compose tools.
Whether it's one-click deployment or quick deployment, these two methods are provided for beginners to experience. For online production deployment, it is recommended to split the deployment. There are three reasons:
- Speed up startup time. Every time you restart the application, you actually only want to restart the geekai-api and geekai-web containers. The quick deployment method restarts all containers each time, which significantly extends the startup time.
- Reduce coupling between containers. For example, the database and Redis containers are usually not only needed for this project. Restarting them may affect other projects.
- Reduce service interruption. For example, if you update the MJ bot account information, you only need to restart the midjourney-proxy container, which will not cause your online service to be interrupted. However, if you are not using split deployment, you will need to restart all containers, which will cause your service to be interrupted.
First, you still need to clone the project:
git clone https://github.com/yangjian102621/geek-ai.git geekai
Split deployment is very simple. It involves deploying each container in the docker-compose.yaml
file independently. The specific split plan can be as follows: except for the last two, geekai-api and geekai-web, which can be deployed together, all other containers need to be split separately. The simplest and most straightforward method is to copy the geekai
directory five times.
cp -r geekai mysql
cp -r geekai redis
Then switch to each directory, edit the docker-compose.yaml
file, keep the corresponding container configuration information, and delete the rest. Taking the MySQL container as an example, the trimmed docker-compose.yaml
file should look like this:
version: '3'
services:
# mysql
geekai-mysql:
image: mysql:8.0.33
container_name: geekai-mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
- MYSQL_ROOT_PASSWORD=12345678
ports:
- "3307:3306"
volumes :
- ./conf/mysql/my.cnf:/etc/mysql/my.cnf
- ./data/mysql/data:/var/lib/mysql
- ./logs/mysql:/var/log/mysql
- ./data/mysql/init.d:/docker-entrypoint-initdb.d/
Other directories should be processed similarly. After processing, the most important step is: modify the configuration files. The advantage of deploying multiple containers in one docker-compose.yaml is that these containers belong to the same internal network, and containers can communicate with each other through container names. However, now that we have split the deployment, containers can only communicate through the host machine's IP address. Therefore, we need to replace all instances of container name communication in the configuration files with IP addresses. There are mainly two configuration files, with four places that need to be replaced. In conf/config.toml, two places need to be replaced: MySQL connection information and Redis connection information.
Assuming your local intranet address is 192.268.1.100, the modified file should look like this:
MysqlDns = "root:12345678@tcp(192.268.1.100:3307)/chatgpt_plus?charset=utf8mb4&collation=utf8mb4_unicode_ci&parseTime=True&loc=Local"
[Redis] # redis configuration
Host = "192.268.1.100"
Port = 6380
Password = "12345678"
DB = 0
After modification, start all containers. If all containers start successfully, the split deployment is complete.