# 堡垒机-tacPort容器化部署

# 容器化部署[​](https://docs.tp4a.com/deploy/containerized.html#%E5%AE%B9%E5%99%A8%E5%8C%96%E9%83%A8%E7%BD%B2)

## 准备工作[​](https://docs.tp4a.com/deploy/containerized.html#%E5%87%86%E5%A4%87%E5%B7%A5%E4%BD%9C)

### 操作系统[​](https://docs.tp4a.com/deploy/containerized.html#%E6%93%8D%E4%BD%9C%E7%B3%BB%E7%BB%9F)

TacPort 支持以 docker 容器的方式进行部署，对应操作系统的要求，也就是对 docker 宿主机系统的要求。例如，您可以在 macOS 系统的 Docker Desktop 环境中部署容器化的 TacPort 节点。

### 初始化数据库[​](https://docs.tp4a.com/deploy/containerized.html#%E5%88%9D%E5%A7%8B%E5%8C%96%E6%95%B0%E6%8D%AE%E5%BA%93)

提示

如果您有数据库管理员账号及密码，可以跳过初始化数据库的步骤，在部署后由 TacPort 来为您创建并初始化数据库。

下面以 MySQL 8.x 为例说明如何为 TacPort 创建库及用户，并授予相应的访问权限。示例中的信息如下：

- 库名：`tacport`
- 用户：`tacport`
- 密码：`Pas5*w0rd`

<div class="language-shell vp-adaptive-theme line-numbers-mode" id="bkmrk-shell" style="box-sizing: border-box; position: relative; margin: 16px 0px; background-color: var(--vp-code-block-bg); overflow-x: auto; transition: background-color 0.5s ease 0s; border-radius: 8px; padding-left: 32px; color: rgb(93, 93, 93); font-family: 'SF Pro Text', 'SF Pro Icons', 'PT Sans', Tahoma, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><button class="copy" style="box-sizing: border-box; touch-action: manipulation; border: 1px solid var(--vp-code-copy-code-border-color); padding: 0px; line-height: inherit; color: inherit; font-family: inherit; background-color: var(--vp-code-copy-code-bg); background-image: var(--vp-icon-copy); cursor: pointer; direction: ltr; position: absolute; top: 12px; right: 12px; z-index: 3; border-radius: 4px; width: 40px; height: 40px; opacity: 0; background-position: 50% center; background-size: 20px; background-repeat: no-repeat; transition: border-color 0.25s ease 0s, background-color 0.25s ease 0s, opacity 0.25s ease 0s;" title="Copy Code"></button><span class="lang" style="box-sizing: border-box; position: absolute; top: 2px; right: 8px; z-index: 2; font-size: 12px; font-weight: 500; user-select: none; color: var(--vp-code-lang-color); transition: color 0.4s ease 0s, opacity 0.4s ease 0s;">shell</span></div>```
# 先以数据库管理员身份连接数据库
mysql -uroot -p
# 此时提示输入密码，请输入数据库root账号的密码
```

<div class="language-shell vp-adaptive-theme line-numbers-mode" id="bkmrk-123" style="box-sizing: border-box; position: relative; margin: 16px 0px; background-color: var(--vp-code-block-bg); overflow-x: auto; transition: background-color 0.5s ease 0s; border-radius: 8px; padding-left: 32px; color: rgb(93, 93, 93); font-family: 'SF Pro Text', 'SF Pro Icons', 'PT Sans', Tahoma, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div aria-hidden="true" class="line-numbers-wrapper" style="box-sizing: border-box; position: absolute; top: 0px; bottom: 0px; left: 0px; z-index: 3; border-right: 1px solid var(--vp-code-block-divider-color); padding-top: 20px; width: 32px; text-align: center; font-family: var(--vp-font-family-mono); line-height: var(--vp-code-line-height); font-size: var(--vp-code-font-size); color: var(--vp-code-line-number-color); transition: border-color 0.5s ease 0s, color 0.5s ease 0s;"><span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">1</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">2</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">3</span>  
</div></div>输入正确的密码后，进入MySQL交互式环境：

<div class="language-sql vp-adaptive-theme line-numbers-mode" id="bkmrk-sql" style="box-sizing: border-box; position: relative; margin: 16px 0px; background-color: var(--vp-code-block-bg); overflow-x: auto; transition: background-color 0.5s ease 0s; border-radius: 8px; padding-left: 32px; color: rgb(93, 93, 93); font-family: 'SF Pro Text', 'SF Pro Icons', 'PT Sans', Tahoma, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><button class="copy" style="box-sizing: border-box; touch-action: manipulation; border: 1px solid var(--vp-code-copy-code-border-color); padding: 0px; line-height: inherit; color: inherit; font-family: inherit; background-color: var(--vp-code-copy-code-bg); background-image: var(--vp-icon-copy); cursor: pointer; direction: ltr; position: absolute; top: 12px; right: 12px; z-index: 3; border-radius: 4px; width: 40px; height: 40px; opacity: 0; background-position: 50% center; background-size: 20px; background-repeat: no-repeat; transition: border-color 0.25s ease 0s, background-color 0.25s ease 0s, opacity 0.25s ease 0s;" title="Copy Code"></button><span class="lang" style="box-sizing: border-box; position: absolute; top: 2px; right: 8px; z-index: 2; font-size: 12px; font-weight: 500; user-select: none; color: var(--vp-code-lang-color); transition: color 0.4s ease 0s, opacity 0.4s ease 0s;">sql</span></div>```
-- 进入MySQL交互式环境后，执行以下SQL语句：
CREATE DATABASE tacport DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_0900_ai_ci;
CREATE USER `tacport`@`localhost` IDENTIFIED BY 'Pas5*w0rd';
GRANT ALL PRIVILEGES ON tacport.* TO `tacport`@`localhost`;
FLUSH PRIVILEGES;

-- 最后执行quit退出MySQL交互式环境
quit;


-- 要改所有主机访问，删除原来的本地用户（可选，如果你不需要限制 localhost 的账号）
DROP USER 'tacport'@'localhost';

-- 重新创建一个任意主机可访问的账号
CREATE USER 'tacport'@'%' IDENTIFIED BY 'Pas5*w0rd';

-- 授权数据库
GRANT ALL PRIVILEGES ON tacport.* TO 'tacport'@'%';

-- 刷新权限
FLUSH PRIVILEGES;

```

<div class="language-sql vp-adaptive-theme line-numbers-mode" id="bkmrk-12345678" style="box-sizing: border-box; position: relative; margin: 16px 0px; background-color: var(--vp-code-block-bg); overflow-x: auto; transition: background-color 0.5s ease 0s; border-radius: 8px; padding-left: 32px; color: rgb(93, 93, 93); font-family: 'SF Pro Text', 'SF Pro Icons', 'PT Sans', Tahoma, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div aria-hidden="true" class="line-numbers-wrapper" style="box-sizing: border-box; position: absolute; top: 0px; bottom: 0px; left: 0px; z-index: 3; border-right: 1px solid var(--vp-code-block-divider-color); padding-top: 20px; width: 32px; text-align: center; font-family: var(--vp-font-family-mono); line-height: var(--vp-code-line-height); font-size: var(--vp-code-font-size); color: var(--vp-code-line-number-color); transition: border-color 0.5s ease 0s, color 0.5s ease 0s;"><span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">1</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">2</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">3</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">4</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">5</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">6</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">7</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">8</span>  
</div></div>### 准备docker镜像[​](https://docs.tp4a.com/deploy/containerized.html#%E5%87%86%E5%A4%87docker%E9%95%9C%E5%83%8F)

提示

如果您能够直接访问 docker.hub 拉取镜像，那么可以跳过本小节，直接进入部署阶段。

因为一些周知的原因，国内难以从 docker.hub 拉取镜像，亦或者拉取镜像非常缓慢，另外就是可能您的环境不允许直接访问外部互联网。有鉴于此，我们提供了预制的 TacPort 节点服务的 docker 镜像文件。

请从 TP4A 的网站上（或者官方QQ群文件）下载docker镜像文件，然后在您本地服务器中导入。下面我们以 tacport v4.0.7-preview 版本为例进行说明。

下载得到的镜像文件名为 `tacport-server-4.0.7-preview-docker-img.tar.gz`，文件为使用 `docker save` 命令导出的并经过了 gnuzip 的压缩。要在您的环境中将镜像导入到 docker 运行环境，请执行：

<div class="vp-code-group vp-adaptive-theme" id="bkmrk-linuxmacos-shell" style="box-sizing: border-box; margin-top: 16px; color: rgb(93, 93, 93); font-family: 'SF Pro Text', 'SF Pro Icons', 'PT Sans', Tahoma, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="tabs" style="box-sizing: border-box; position: relative; display: flex; margin-right: 0px; margin-left: 0px; padding: 0px 12px; background-color: var(--vp-code-tab-bg); overflow: auto hidden; box-shadow: inset 0 -1px var(--vp-code-tab-divider); border-radius: 8px 8px 0px 0px;"><label data-title="Linux" for="tab-nL8BN_w" style="box-sizing: border-box; touch-action: manipulation; position: relative; display: inline-block; border-bottom: 1px solid transparent; padding: 0px 12px; line-height: 48px; font-size: 14px; font-weight: 500; color: var(--vp-code-tab-active-text-color); white-space: nowrap; cursor: pointer; transition: color 0.25s ease 0s;">Linux</label><label data-title="macOS" for="tab-9uLE1SS" style="box-sizing: border-box; touch-action: manipulation; position: relative; display: inline-block; border-bottom: 1px solid transparent; padding: 0px 12px; line-height: 48px; font-size: 14px; font-weight: 500; color: var(--vp-code-tab-text-color); white-space: nowrap; cursor: pointer; transition: color 0.25s ease 0s;">macOS</label></div><div class="blocks" style="box-sizing: border-box;"><div class="language-shell vp-adaptive-theme active line-numbers-mode" style="box-sizing: border-box; display: block; margin: 16px 0px; border-radius: 8px; position: relative; background-color: var(--vp-code-block-bg); overflow-x: auto; transition: background-color 0.5s ease 0s; padding-left: 32px;"><button class="copy" style="box-sizing: border-box; touch-action: manipulation; border: 1px solid var(--vp-code-copy-code-border-color); padding: 0px; line-height: inherit; color: inherit; font-family: inherit; background-color: var(--vp-code-copy-code-bg); background-image: var(--vp-icon-copy); cursor: pointer; direction: ltr; position: absolute; top: 12px; right: 12px; z-index: 3; border-radius: 4px; width: 40px; height: 40px; opacity: 0; background-position: 50% center; background-size: 20px; background-repeat: no-repeat; transition: border-color 0.25s ease 0s, background-color 0.25s ease 0s, opacity 0.25s ease 0s;" title="Copy Code"></button><span class="lang" style="box-sizing: border-box; position: absolute; top: 2px; right: 8px; z-index: 2; font-size: 12px; font-weight: 500; user-select: none; color: var(--vp-code-lang-color); transition: color 0.4s ease 0s, opacity 0.4s ease 0s;">shell</span></div></div></div>```
gnuzip -c ./tacport-server-4.0.7-preview-docker-img.tar.gz | docker load

# 在较新的系统上，没有gnuzip，也可以使用gzip命令：
gzip -c -d ./tacport-server-4.0.7-preview-docker-img.tar.gz | docker load
```

<div class="vp-code-group vp-adaptive-theme" id="bkmrk-1234" style="box-sizing: border-box; margin-top: 16px; color: rgb(93, 93, 93); font-family: 'SF Pro Text', 'SF Pro Icons', 'PT Sans', Tahoma, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="blocks" style="box-sizing: border-box;"><div class="language-shell vp-adaptive-theme active line-numbers-mode" style="box-sizing: border-box; display: block; margin: 16px 0px; border-radius: 8px; position: relative; background-color: var(--vp-code-block-bg); overflow-x: auto; transition: background-color 0.5s ease 0s; padding-left: 32px;"><div aria-hidden="true" class="line-numbers-wrapper" style="box-sizing: border-box; position: absolute; top: 0px; bottom: 0px; left: 0px; z-index: 3; border-right: 1px solid var(--vp-code-block-divider-color); padding-top: 20px; width: 32px; text-align: center; font-family: var(--vp-font-family-mono); line-height: var(--vp-code-line-height); font-size: var(--vp-code-font-size); color: var(--vp-code-line-number-color); transition: border-color 0.5s ease 0s, color 0.5s ease 0s;"><span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">1</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">2</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">3</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">4</span>  
</div></div></div></div>注意

导入的镜像自带版本号为标签，方便后期进行版本管理。

提示

镜像名称会在很多地方引用，例如docker-compose的配置文件中。为避免每次升级后因镜像名称变动而重新修改这些引用镜像名称的地方，可以对导入的镜像设置一个通用的镜像标签，常见的做法是总是为最新的版本打上`latest`标签，例如：

<div class="language-shell vp-adaptive-theme line-numbers-mode" id="bkmrk-shell-1" style="box-sizing: border-box; position: relative; margin: 16px 0px; background-color: var(--vp-code-block-bg); overflow-x: auto; transition: background-color 0.5s ease 0s; border-radius: 8px; padding-left: 32px; color: rgb(93, 93, 93); font-family: 'SF Pro Text', 'SF Pro Icons', 'PT Sans', Tahoma, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><button class="copy" style="box-sizing: border-box; touch-action: manipulation; border: 1px solid var(--vp-code-copy-code-border-color); padding: 0px; line-height: inherit; color: inherit; font-family: inherit; background-color: var(--vp-code-copy-code-bg); background-image: var(--vp-icon-copy); cursor: pointer; direction: ltr; position: absolute; top: 12px; right: 12px; z-index: 3; border-radius: 4px; width: 40px; height: 40px; opacity: 0; background-position: 50% center; background-size: 20px; background-repeat: no-repeat; transition: border-color 0.25s ease 0s, background-color 0.25s ease 0s, opacity 0.25s ease 0s;" title="Copy Code"></button><span class="lang" style="box-sizing: border-box; position: absolute; top: 2px; right: 8px; z-index: 2; font-size: 12px; font-weight: 500; user-select: none; color: var(--vp-code-lang-color); transition: color 0.4s ease 0s, opacity 0.4s ease 0s;">shell</span></div>```
docker tag tp4a/tacport:4.0.7-preview tp4a/tacport:latest
```

<div class="language-shell vp-adaptive-theme line-numbers-mode" id="bkmrk-1" style="box-sizing: border-box; position: relative; margin: 16px 0px; background-color: var(--vp-code-block-bg); overflow-x: auto; transition: background-color 0.5s ease 0s; border-radius: 8px; padding-left: 32px; color: rgb(93, 93, 93); font-family: 'SF Pro Text', 'SF Pro Icons', 'PT Sans', Tahoma, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div aria-hidden="true" class="line-numbers-wrapper" style="box-sizing: border-box; position: absolute; top: 0px; bottom: 0px; left: 0px; z-index: 3; border-right: 1px solid var(--vp-code-block-divider-color); padding-top: 20px; width: 32px; text-align: center; font-family: var(--vp-font-family-mono); line-height: var(--vp-code-line-height); font-size: var(--vp-code-font-size); color: var(--vp-code-line-number-color); transition: border-color 0.5s ease 0s, color 0.5s ease 0s;"><span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">1</span>  
</div></div>之后，您就可以在需要使用镜像名称的地方，总是使用`tp4a/tacport:latest`来引用最新版本的 TacPort 镜像了。

## 部署[​](https://docs.tp4a.com/deploy/containerized.html#%E9%83%A8%E7%BD%B2)

容器化部署有多种方式，例如 docker run，docker-compose，或者 K8s 等。我们这里以 docker-compose 为例进行部署说明。

注意

以下部署示例中，MySQL 和 Redis 均部署在运行 docker 的宿主机上，因此，在容器中访问宿主机上的服务时，宿主机可以通过 `host.docker.internal` 来访问。

如果您的环境并非如此，请在您的 docker-compose 配置文件中修改其服务地址。例如，访问其它容器中的服务，可以直接使用该服务所在的容器名作为主机地址。

在合适的目录中创建 `docker-compose.yaml` 文件，如果您已经有使用中的 docker-compose 配置文件，也可以在原配置文件基础上增加 TacPort 节点服务的内容。

### docker-compose 配置示例[​](https://docs.tp4a.com/deploy/containerized.html#docker-compose-%E9%85%8D%E7%BD%AE%E7%A4%BA%E4%BE%8B)

下面是一个运行 TacPort 服务的 docker-compose 配置文件示例：

<div class="vp-code-block-title" id="bkmrk-docker-compose.yaml-" style="box-sizing: border-box; color: rgb(93, 93, 93); font-family: 'SF Pro Text', 'SF Pro Icons', 'PT Sans', Tahoma, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="vp-code-block-title-bar" style="box-sizing: border-box; position: relative; margin: 16px 0px 0px; background-color: var(--vp-code-block-bg); overflow-x: auto; font-size: 14px; font-weight: 500; color: var(--vp-code-tab-text-color); white-space: nowrap; transition: background-color 0.5s ease 0s; border-radius: 8px 8px 0px 0px; padding: 0px 12px; box-shadow: inset 0 -1px var(--vp-code-tab-divider);"><span class="vp-code-block-title-text" data-title="docker-compose.yaml" style="box-sizing: border-box; padding: 0px 12px; line-height: 48px;">docker-compose.yaml</span></div><div class="language-yaml vp-adaptive-theme line-numbers-mode" style="box-sizing: border-box; position: relative; background-color: var(--vp-code-block-bg); overflow-x: auto; transition: background-color 0.5s ease 0s; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px; padding-left: 32px; margin: 0px !important 0px 16px 0px;"><button class="copy" style="box-sizing: border-box; touch-action: manipulation; border: 1px solid var(--vp-code-copy-code-border-color); padding: 0px; line-height: inherit; color: inherit; font-family: inherit; background-color: var(--vp-code-copy-code-bg); background-image: var(--vp-icon-copy); cursor: pointer; direction: ltr; position: absolute; top: 12px; right: 12px; z-index: 3; border-radius: 4px; width: 40px; height: 40px; opacity: 0; background-position: 50% center; background-size: 20px; background-repeat: no-repeat; transition: border-color 0.25s ease 0s, background-color 0.25s ease 0s, opacity 0.25s ease 0s;" title="Copy Code"></button><span class="lang" style="box-sizing: border-box; position: absolute; top: 2px; right: 8px; z-index: 2; font-size: 12px; font-weight: 500; user-select: none; color: var(--vp-code-lang-color); transition: color 0.4s ease 0s, opacity 0.4s ease 0s;">yaml</span></div></div>```
services:
  tpnode1:
    image: tp4a/tacport:latest
    container_name: tpv4-node-1
    ports:
      - "7100:52100"
      - "7101:52101"
    environment:
      - TP_ALLOW_INIT=yes
      - TP_NODE_ID=1
      - TP_NODE_ADDR=tpv4.tp4a.com
      - TP_DB_ADDR=host.docker.internal:3306
      - TP_DB_USER=tacport
      - TP_DB_NAME=tacport
      - TP_DB_PASS=Pas5*w0rd
      - TP_SECRET_KEY=48V2%9+zmT
      - TP_REDIS_ADDR=host.docker.internal:6379
      - TP_NODE_SERVICE=api,ssh
      - TP_API_MAPPING_PORT=7100
      - TP_SSH_MAPPING_PORT=7101

    volumes:
      - /nfs-data/tacport-data:/opt/tacport/data
    deploy:
      resources:
        limits:
          cpus: "0.5"
          memory: 1024M
```

<div class="vp-code-block-title" id="bkmrk-12345678910111213141" style="box-sizing: border-box; color: rgb(93, 93, 93); font-family: 'SF Pro Text', 'SF Pro Icons', 'PT Sans', Tahoma, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="language-yaml vp-adaptive-theme line-numbers-mode" style="box-sizing: border-box; position: relative; background-color: var(--vp-code-block-bg); overflow-x: auto; transition: background-color 0.5s ease 0s; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px; padding-left: 32px; margin: 0px !important 0px 16px 0px;"><div aria-hidden="true" class="line-numbers-wrapper" style="box-sizing: border-box; position: absolute; top: 0px; bottom: 0px; left: 0px; z-index: 3; border-right: 1px solid var(--vp-code-block-divider-color); padding-top: 20px; width: 32px; text-align: center; font-family: var(--vp-font-family-mono); line-height: var(--vp-code-line-height); font-size: var(--vp-code-font-size); color: var(--vp-code-line-number-color); transition: border-color 0.5s ease 0s, color 0.5s ease 0s;"><span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">1</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">2</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">3</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">4</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">5</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">6</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">7</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">8</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">9</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">10</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">11</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">12</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">13</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">14</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">15</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">16</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">17</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">18</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">19</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">20</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">21</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">22</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">23</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">24</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">25</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">26</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">27</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">28</span>  
</div></div></div>下文将对此配置文件进行详细说明。

提示

您也可以使用 docker-compose 的 `env_file` 方式来提供环境变量。

警告

出于示例理解的考虑，这里的docker-compose配置文件中直接在环境变量中写入了密码/密钥等私密数据。实际应用时，应该使用docker-compose提供的`secrets`来保证安全性。

### docker-compose 配置详解[​](https://docs.tp4a.com/deploy/containerized.html#docker-compose-%E9%85%8D%E7%BD%AE%E8%AF%A6%E8%A7%A3)

需要重点关注通过环境变量方式对 TacPort 节点服务进行的配置。如果您对于配置项的作用不甚了解，可以查看[配置项::环境变量](https://docs.tp4a.com/deploy/configuration.html#%E7%8E%AF%E5%A2%83%E5%8F%98%E9%87%8F)一文。

<div class="vp-code-block-title" id="bkmrk-docker-compose.yaml--1" style="box-sizing: border-box; color: rgb(93, 93, 93); font-family: 'SF Pro Text', 'SF Pro Icons', 'PT Sans', Tahoma, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="vp-code-block-title-bar" style="box-sizing: border-box; position: relative; margin: 16px 0px 0px; background-color: var(--vp-code-block-bg); overflow-x: auto; font-size: 14px; font-weight: 500; color: var(--vp-code-tab-text-color); white-space: nowrap; transition: background-color 0.5s ease 0s; border-radius: 8px 8px 0px 0px; padding: 0px 12px; box-shadow: inset 0 -1px var(--vp-code-tab-divider);"><span class="vp-code-block-title-text" data-title="docker-compose.yaml" style="box-sizing: border-box; padding: 0px 12px; line-height: 48px;">docker-compose.yaml</span></div><div class="language-yaml vp-adaptive-theme line-numbers-mode" style="box-sizing: border-box; position: relative; background-color: var(--vp-code-block-bg); overflow-x: auto; transition: background-color 0.5s ease 0s; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px; padding-left: 32px; margin: 0px !important 0px 16px 0px;"><button class="copy" style="box-sizing: border-box; touch-action: manipulation; border: 1px solid var(--vp-code-copy-code-border-color); padding: 0px; line-height: inherit; color: inherit; font-family: inherit; background-color: var(--vp-code-copy-code-bg); background-image: var(--vp-icon-copy); cursor: pointer; direction: ltr; position: absolute; top: 12px; right: 12px; z-index: 3; border-radius: 4px; width: 40px; height: 40px; opacity: 0; background-position: 50% center; background-size: 20px; background-repeat: no-repeat; transition: border-color 0.25s ease 0s, background-color 0.25s ease 0s, opacity 0.25s ease 0s;" title="Copy Code"></button><span class="lang" style="box-sizing: border-box; position: absolute; top: 2px; right: 8px; z-index: 2; font-size: 12px; font-weight: 500; user-select: none; color: var(--vp-code-lang-color); transition: color 0.4s ease 0s, opacity 0.4s ease 0s;">yaml</span></div></div>```
services: # 定义要运行的服务
  tpnode1: # 服务的名称
    image: tp4a/tacport:latest # 创建此服务容器需要的镜像
    container_name: tpv4-node-1 # 创建的服务容器的名称
    ports: # 端口映射，冒号前为宿主机上的映射端口，后为容器内部的服务监听端口
      - "7100:52100" # 将默认的api服务端口 52100 映射到宿主机上的 7100 端口
      - "7101:52101" # 将默认的ssh协议转发服务端口 52101 映射到宿主机上的 7101 端口
    environment: # 通过环境变量的方式对 TacPort 节点服务进行配置
      - TP_ALLOW_INIT=yes # 首次部署时，允许执行初始化操作（初始化完成后请删除此项，或改为no，以增强安全性）
      - TP_NODE_ID=1 # 节点编号，多个节点实例需保证各个实例的节点编号唯一
      - TP_NODE_ADDR=tpv4.tp4a.com
      - TP_DB_ADDR=host.docker.internal:3306 # 容器内访问宿主机时可以用 host.docker.internal
      - TP_DB_USER=tacport # 可以省略，即，使用默认值
      - TP_DB_NAME=tacport # 可以省略，即，使用默认值
      - TP_DB_PASS=Pas5*w0rd # 建议使用 secrets 来管理私密数据
      - TP_SECRET_KEY=48V2%9+zmT # 建议使用 secrets 来管理私密数据
      - TP_REDIS_ADDR=host.docker.internal:6379
      - TP_NODE_SERVICE=api,ssh # 本节点提供API服务和SSH协议转发服务
      - TP_API_MAPPING_PORT=7100 # 需指明映射的宿主机的端口
      - TP_SSH_MAPPING_PORT=7101

    volumes: # 容器持久化存储，映射卷来存放配置/日志/审计录像文件等等。
      - ./data/tacport:/opt/tacport/data
    deploy: # 指定此容器的资源限制，请根据实际负载进行调整
      resources:
        limits:
          cpus: "0.5"
          memory: 1024M
```

<div class="vp-code-block-title" id="bkmrk-12345678910111213141-1" style="box-sizing: border-box; color: rgb(93, 93, 93); font-family: 'SF Pro Text', 'SF Pro Icons', 'PT Sans', Tahoma, 'Helvetica Neue', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', 微软雅黑, Helvetica, Arial, sans-serif; font-size: 16px; font-style: normal; font-variant-ligatures: normal; font-variant-caps: normal; font-weight: 400; letter-spacing: normal; orphans: 2; text-align: start; text-indent: 0px; text-transform: none; widows: 2; word-spacing: 0px; -webkit-text-stroke-width: 0px; white-space: normal; background-color: rgb(255, 255, 255); text-decoration-thickness: initial; text-decoration-style: initial; text-decoration-color: initial;"><div class="language-yaml vp-adaptive-theme line-numbers-mode" style="box-sizing: border-box; position: relative; background-color: var(--vp-code-block-bg); overflow-x: auto; transition: background-color 0.5s ease 0s; border-top-left-radius: 0px !important; border-top-right-radius: 0px !important; border-bottom-right-radius: 8px; border-bottom-left-radius: 8px; padding-left: 32px; margin: 0px !important 0px 16px 0px;"><div aria-hidden="true" class="line-numbers-wrapper" style="box-sizing: border-box; position: absolute; top: 0px; bottom: 0px; left: 0px; z-index: 3; border-right: 1px solid var(--vp-code-block-divider-color); padding-top: 20px; width: 32px; text-align: center; font-family: var(--vp-font-family-mono); line-height: var(--vp-code-line-height); font-size: var(--vp-code-font-size); color: var(--vp-code-line-number-color); transition: border-color 0.5s ease 0s, color 0.5s ease 0s;"><span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">1</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">2</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">3</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">4</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">5</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">6</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">7</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">8</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">9</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">10</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">11</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">12</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">13</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">14</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">15</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">16</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">17</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">18</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">19</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">20</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">21</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">22</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">23</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">24</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">25</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">26</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">27</span>  
<span class="line-number" style="box-sizing: border-box; font-size: 11.2px; font-family: 'Operator Mono', Monaco, 'Lucida Console', Consolas, Courier, 'Courier New', monospace;">28</span>  
</div></div></div>### 启动服务[​](https://docs.tp4a.com/deploy/containerized.html#%E5%90%AF%E5%8A%A8%E6%9C%8D%E5%8A%A1)

执行 `docker compose up` 来启动服务，此时可以从控制台看到节点服务的日志输出，按 `Ctrl+C` 来结束服务。可以增加参数 `-d` 来将服务放到后台运行（比较控制台关闭时将服务也关闭了），像这样：`docker compose up -d`。

服务启动后，可以访问 `http://TP_容器宿主机IP:API服务映射端口` 来访问 TacPort 服务了，在本例中，地址为 `http://TP_容器宿主机IP:7100`。

如同常规部署一样，如果运行时检测到数据库尚未创建或初始化，需要访问初始化页面，参见 [常规配置：初始化](https://docs.tp4a.com/deploy/regular.html#%E5%88%9D%E5%A7%8B%E5%8C%96) 一节。在本例中，初始化页面地址为 `http://TP_容器宿主机IP:7100/init`。

## 服务日常管理[​](https://docs.tp4a.com/deploy/containerized.html#%E6%9C%8D%E5%8A%A1%E6%97%A5%E5%B8%B8%E7%AE%A1%E7%90%86)

#### 使用docker命令管理镜像[​](https://docs.tp4a.com/deploy/containerized.html#%E4%BD%BF%E7%94%A8docker%E5%91%BD%E4%BB%A4%E7%AE%A1%E7%90%86%E9%95%9C%E5%83%8F)

- 查看服务：`docker ps`
- 查看镜像：`docker images`
- 为镜像打tag: `docker tag 源镜像名[:TAG] 新镜像名[:TAG]`，例如：`docker tag tp4a/tacport:4.0.7 tp4a/tacport:latest`。需要注意的是，打完tag之后，原来的`镜像:tag`还是存在的，如果原来的标签不需要再使用了，可以将其删除。
- 删除镜像/标签：`docker rmi 镜像名[:TAG]`，一个镜像可以有多个标签，当最后一个标签被删除时，才会删除镜像本身。

#### 使用 docker-compose管理服务[​](https://docs.tp4a.com/deploy/containerized.html#%E4%BD%BF%E7%94%A8-docker-compose%E7%AE%A1%E7%90%86%E6%9C%8D%E5%8A%A1)

以下操作需在 docker-compose 配置文件所在目录下执行，或者命令行上用 `-f` 参数来指定配置文件。

- 启动服务：`docker compose up -d` 其中 `-d` 参数可将docker-compose进程放到后台执行
- 停止服务：`docker compose down`
- 重启服务：修改了配置文件后，重新执行 `docker-compose up -d` 即可
- 重启某个服务：`docker compose restart 服务名`，例如，重启第一个节点服务，可以 `docker compose restart tpnode1`
- 查看服务：`docker compose ps`
- 查看状态：`docker compose stats` 查看各容器实时负载状态，按`Ctrl-C`退出