You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
docs/docs/getting-started/install/docker.md

97 lines
3.0 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: 使用 Docker 部署
description: 使用 Docker 部署
---
:::info
在继续操作之前,我们推荐您先阅读[《写在前面》](../prepare),这可以快速帮助你了解 Halo。
:::
## 使用 Docker 镜像
可用的 Halo 2.0.0-alpha.1 的 Docker 镜像:
- [halohub/halo-dev](https://hub.docker.com/r/halohub/halo-dev)
- [ghcr.io/halo-dev/halo-dev](https://github.com/halo-dev/halo/pkgs/container/halo-dev)
> 注意:以上两个镜像仅作为 Halo 2.0 测试期间的镜像,正式发布之后会更改为 `halohub/halo` 和 `ghcr.io/halo-dev/halo`。
1. 创建容器
```bash
docker run \
-it -d \
--name halo-next \
-p 8090:8090 \
-v ~/halo-next:/root/halo-next \
-e HALO_EXTERNAL_URL=http://localhost:8090/ \ # 请修改外部访问链接
-e HALO_SECURITY_INITIALIZER_SUPERADMINPASSWORD=P@88w0rd \ # 请修改管理员密码
halohub/halo-dev:2.0.0-alpha.1
```
:::info
注意:此命令默认使用自带的 H2 Database 数据库。如需使用 PostgreSQL请参考[使用 Docker Compose 部署](./docker-compose)
:::
- **-it** 开启输入功能并连接伪终端
- **-d** 后台运行容器
- **--name** 为容器指定一个名称
- **-p** 端口映射,格式为 `主机(宿主)端口:容器端口` ,可在 `application.yaml` 配置。
- **-v** 工作目录映射。形式为:`-v 宿主机路径:/root/halo-next`,后者不能修改。
- **--restart** 建议设置为 `unless-stopped`,在 Docker 启动的时候自动启动 Halo 容器。
1. 用浏览器访问 `$HALO_EXTERNAL_URL/console/`(外部访问链接)即可进入 Halo 管理端。
:::tip
如果需要配置域名访问,建议先配置好反向代理以及域名解析再进行初始化。如果通过 `http://ip:端口号` 的形式无法访问,请到服务器厂商后台将运行的端口号添加到安全组,如果服务器使用了 Linux 面板,请检查此 Linux 面板是否有还有安全组配置,需要同样将端口号添加到安全组。
:::
## 反向代理
你可以在下面的反向代理软件中任选一项,我们假设你已经安装好了其中一项,并对其的基本操作有一定了解。如果你对 Nginx 不熟悉,我们推荐使用 [OneinStack](./other/oneinstack) 来管理 Nginx。
### Nginx
```nginx
upstream halo {
server 127.0.0.1:8090;
}
server {
listen 80;
listen [::]:80;
server_name www.yourdomain.com;
client_max_body_size 1024m;
location / {
proxy_pass http://halo;
proxy_set_header HOST $host;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
```
### Caddy 1.x
```txt
https://www.yourdomain.com {
gzip
tls your@email.com
proxy / localhost:8090 {
transparent
}
}
```
### Caddy 2.x
```txt
www.yourdomain.com
encode gzip
reverse_proxy 127.0.0.1:8090
```
以上配置都可以在 <https://github.com/halo-dev/halo-common> 找到。