上次安装好了sql server容器,但是appsmith创建数据源出现连接错误:
[2024-01-30 00:25:52,186] userEmail=tt@app.com, sessionId=b99a2476-5c35-4a71-9e8e-25c9c3292cfa, thread=boundedElastic-38, requestId=ea262c1d-722b-4176-aac7-4b062d7066b6 - Operator called default onErrorDropped
com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException: Exception occurred while creating connection pool. One or more arguments in the datasource configuration may be invalid. Please check your datasource configuration.
日志看不出所以然。但是似乎是两个容器之间的网络不通,于是又学习了点知识,继续再战。
每次运行Docker run是很麻烦的,多个容器的启动更麻烦,而Compose 是用于定义和运行多容器 Docker 应用程序的工具,通过 Compose使用 YML 文件来配置应用程序需要的所有服务。然后,使用一个命令从 YML 文件配置中创建并启动所有服务。
开干!
step1.先创建一个自定义网络网络
[root@localhost mssql]# docker network create --driver bridge --subnet 172.168.0.0/24 --gateway 172.168.0.1 appsmith_sqlserver
540e83d5fd88cab6ff28a2ae55b862b1b145bdd9fe66374b46f8c10f46b4936b
step2.创建一个文件夹,其下建yml文件
在/home/mssql 下创建一个dock-compose.yml,内容如下
[root@localhost mssql]# cat docker-compose.yml
version: "3"
services:
appsmith:
image: index.docker.io/appsmith/appsmith-ce
container_name: appsmith
ports:
- "80:80"
- "443:443"
volumes:
- ./stacks:/appsmith-stacks
restart: unless-stopped
networks:
- appsmith_sqlserver
mssql:
image: mcr.microsoft.com/mssql/server:2022-latest
container_name: mssql
restart: always
hostname: mssql
environment:
#接受最终用户许可协议
- ACCEPT_EULA=Y
#SA用户密码,密码长度必须至少为8个字符,并且包含以下四组中的三组字符:大写字母、小写字母、数字和符号。
- MSSQL_SA_PASSWORD=2025@Passw0rd
- MSSQL_PID=Express
ports:
- 1433:1433
volumes:
- /home/sql_db_files:/var/opt/mssql
networks:
- appsmith_sqlserver
networks:
appsmith_sqlserver:
driver: bridge
建文件不难,主要要细心,否则yml文件不是这行错就是那行错,如果出错,你可以用yaml在线校验工具验证一下。
step3.启动容器
[root@localhost mssql]# docker compose up -d
[+] Running 2/3
⠦ Network mssql_appsmith_sqlserver Created 0.6s
✔ Container appsmith Started 0.5s
✔ Container mssql Started
step4.查看容器的IP信息
[root@localhost mssql]# docker network ls
NETWORK ID NAME DRIVER SCOPE
b875cddf1acd appsmith_default bridge local
540e83d5fd88 appsmith_sqlserver bridge local
dc7aec8cad2b bridge bridge local
e4a4591b8a36 host host local
27e5417bd70b mssql_appsmith_sqlserver bridge local
f173df622cec none null local
945d5b503344 sql_db_files_default bridge local
[root@localhost mssql]# docker network inspect appsmith_sqlserver
[
{
"Name": "appsmith_sqlserver",
"Id": "540e83d5fd88cab6ff28a2ae55b862b1b145bdd9fe66374b46f8c10f46b4936b",
"Created": "2024-01-30T08:16:10.209740601-05:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": {},
"Config": [
{
"Subnet": "172.168.0.0/24",
"Gateway": "172.168.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {},
"Options": {},
"Labels": {}
}
]
我创建的appsmith_sqlserver网络里面根本没有两个容器分配的IP地址!!
但是现在冒出一个带有文件夹前缀的网络 mssql_appsmith_sqlserver,里面有两个容器的IP地址,也就是说,我第一步的操作无效。
[root@localhost mssql]# docker network inspect mssql_appsmith_sqlserver
[
{
"Name": "mssql_appsmith_sqlserver",
"Id": "27e5417bd70bc0d2974270ee00bd1942e17d15a2c5af28c587a188df5c9d5667",
"Created": "2024-01-30T08:24:41.296757253-05:00",
"Scope": "local",
"Driver": "bridge",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "172.21.0.0/16",
"Gateway": "172.21.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"76aea4fa4882b5038641b8a454b774c9fa36348237d80a58ecce27496334f641": {
"Name": "mssql",
"EndpointID": "ecf7cdf572de8c3af2117af35ca6605c2e8ce1a857dd7926ab9e5cfbc771a3dc",
"MacAddress": "02:42:ac:15:00:03",
"IPv4Address": "172.21.0.3/16",
"IPv6Address": ""
},
"8c909e8306f791162da66662239e6a7e0135af4df0fc41519de2ad1555830dcd": {
"Name": "appsmith",
"EndpointID": "051aa5cd5f6eda7c99831c5db6d407d1fdf7cf0ca4034742b7ce59b81e0f1249",
"MacAddress": "02:42:ac:15:00:02",
"IPv4Address": "172.21.0.2/16",
"IPv6Address": ""
}
},
"Options": {},
"Labels": {
"com.docker.compose.network": "appsmith_sqlserver",
"com.docker.compose.project": "mssql",
"com.docker.compose.version": "2.24.1"
}
}
]
step5.连接容器,创建数据库
[root@localhost data]# docker exec -it mssql "bash"
mssql@mssql2022:/$ /opt/mssql-tools/bin/sqlcmd -S localhost -U SA -P 2025@Passw0rd
1> create database testdatabase
2> ;
3> go
1>
step6.appsmith里面配置数据库连接
顺顺利利
至此appsmith和数据库的连接环境就搭建好的,后面可以进一步探索了。
这次安装中,还是碰到几个小水坑的:
水坑1:[root@localhost appsmith]# docker logs 84f18f951d0a
/opt/mssql/bin/sqlservr: Error: The system directory [/.system] could not be created. File: LinuxDirectory.cpp:420 [Status: 0xC0000022 Access Denied errno = 0xD(13) Permission denied]
从日志可以看出是权限问题。
--改owner
[root@localhost home]# chown -R docker:docker /home/sql_db_files
--改owner
[root@localhost home]# chown -R 10001:0 /home/sql_db_files
--添加用户,加组
[root@localhost home]# adduser -u 10001 mssql
[root@localhost home]# usermod -aG docker $USER
折腾好几次才发现,确实是和权限有关系,但最要原因是出在映射文件目录错误导致。
水坑2:容器里面创建了数据库,在sql server管理控制台中看不到;
主要是习惯了查询分析器,所以忘记go了!
1> create database workshop_batch
2> ;
3> go
1> exit
mssql@mssql2022:/$ exit
水坑3:如果前面已经创建了mssql容器,提示已存在,可以使用rm删除
[root@localhost appsmith]# docker rm -f mssql
水坑4:每一个yml文件都会创建一个网络
即使指定了网络也不行,所以只能那两个容器都包在一个yml文件中,理论应该是可以,只是我对Docker容器网络了解还不够。