---
title: "UE4 Container"
author: "AVI"
date: "2022-02-17T11:15:59Z"
tags: []
categories: ["行业应用"]
slug: "ue4-container"
draft: false
lastmod: "2022-02-18T10:58:59Z"
id: 2524392
url: "https://avi.iteye.com/blog/2524392"
---

- 仍处于测试阶段。目前仅包含 Linux 开发镜像，无 Windows 开发镜像（由于技术和法律限制，官方无法发布 Windows 开发镜像）。所有支持像素流的 Windows 运行时镜像都支持基于 NVIDIA 和 AMD 显卡的 GPU 加速。Linux 镜像只支持 NVIDIA 显卡，对AMD 显卡的支持将在未来推出。
- E4 Container 基于 [TensorWorks](https://tensorworks.com.au/)开源架构开发，并由 [虚幻容器](https://unrealcontainers.com/) 社区维护。
- E4 Container 的作用：增强生产管线，开发次世代云应用程序，大规模部署企业解决方案等。
- UE4 Container 属于轻量级的，以容器镜像的方式存储在磁盘上，通过 Image 可运行一个或多个 Container 。与虚拟机不同的是，Container 共享一个底层 OS 内核，可跨不同 Container Image 共享公共数据，并能实现大量并发部署。 容器的应用标准单元可在不同计算基础设备（包括本地设备和云端设备）之间迁移。
- 包含两种容器镜像：开发镜像（Dev Images）和运行时镜像（Runtime Images）。4.27 版本中共有 7 中镜像类型。

 

**开发镜像与运行时镜像对比**：

 

1、开发镜像用于需要编辑器的任务，在法律上有严格的 EULA 限制来管理它们的分发。

 

包含内容：

- （必需）： Engine 构建工具和 Editor
- （可选）：非核心引擎组件，如模板项目、调试符号和派生数据缓存 (DDC)
- （可选）：使虚幻编辑器能够渲染图形所需的运行时依赖项和配置文件
- （可选）：在 Linux 下将虚幻编辑器作为沙盒 GUI 应用程序运行所需的运行时依赖项和配置文件
- （可选）：使用 X11 转发通过 VNC 或 SSH 远程访问虚幻编辑器所需的运行时依赖项和配置文件
- （可选）：其他第三方附加功能或开源工具，例如 ue4cli

执行任务：

- 在容器中构建和打包项目或插件
- 为容器内的 Unreal 项目运行自动化测试工作流程
- 运行命令行功能为容器内的 Unreal 项目烘焙光照、烘培内容、电影渲染或执行其他任务
- 为容器内的 Unreal 项目渲染 Sequencer 过场动画
- 在容器内运行 Python 脚本或其他编辑器自动化实用程序

2、运行时映像用于运行打包的项目，包含打包的 Unreal 项目及其运行时依赖项，并且可以更自由地分发。

 

包含内容：

- （必需）：运行带离屏渲染的打包虚幻项目所需的运行时依赖项
- （可选）：启用音频输出所需的运行时依赖项和配置文件
- （可选）：使用 Pixel Streaming 远程访问打包的 Unreal 项目所需的运行时依赖项和配置文件
- （可选）：使用 X11 转发通过 VNC 或 SSH 远程访问打包的 Unreal 项目所需的运行时依赖项和配置文件
- （可以通过扩展基础镜像或绑定挂载文件自行添加）：自定义在容器中运行的打包虚幻项目

执行任务：

- 使用 Engine 开发映像在容器内构建和打包项目，然后在容器内运行它
- 在容器外构建和打包项目，然后在容器内运行

3、可用镜像容器。

 

容器镜像的源代码：`Engine/Extras/Containers.`

容器镜像的预构建版本：[GitHub 容器注册表](https://docs.github.com/en/packages/working-with-a-github-packages-registry/working-with-the-container-registry)。

 

镜像 镜像类型 描述 **dev** 开发镜像 虚幻引擎的完整 Linux 开发镜像，包括虚幻引擎的已安装版本、模板项目和完整调试符号。 **dev-slim** 开发镜像 Linux 版本的开发镜像，内容较小，不包含模板项目和调试符号。 **runtime** 运行时镜像 带有或未带有 GPU 加速的简化版 Linux 运行时镜像，专用于在容器内运行打包的虚幻引擎应用程序。为了将镜像大小压缩到最小，此镜像不支持音频输出。 此容器镜像目前仅对使用 NVIDIA GPU 的机器提供 GPU 加速支持。 **runtime-pixel-streaming** 运行时镜像 此镜像扩展了简化版 Linux 运行时镜像，以添加像素流应用程序所需的依赖项，包括支持音频输出。因此，尽管此镜像仍比 Windows 运行时镜像要小得多，但明显比默认运行时镜像要大。此容器镜像目前仅支持 NVIDIA GPU 的 GPU 加速。 **runtime-windows** 运行时镜像 带有或未带有 GPU 加速的 Windows 运行时镜像，专用于在容器内运行打包的虚幻引擎应用程序。由于 Windows 容器镜像已经比 Linux 容器镜像大很多，而且与 Windows 操作系统本身的大小相比，像素流应用程序所需的依赖项相对较小，因此该镜像也包含这些依赖项。目前，对于在基于 GPU 加速的 Windows 容器内运行像素流应用的支持还是试验性的，不建议在实际开发中使用。 **pixel-streaming-signalling-server** 特殊镜像 包括像素流系统使用的 Cirrus 信号和 web 服务器的 Linux 容器镜像。 **multi-user-server** 特殊镜像 包括虚幻引擎多用户编辑系统所用服务器的 Linux 容器镜像。

 不同的用例可能需要这些类型的容器映像中的一种或两种。

 

4、软件及硬件要求。

 包含在虚幻引擎中的 Linux 容器镜像可以在 Windows、macOS 或 Linux 上构建和运行。计算机需满足以下硬件要求：

- 64 位 CPU，支持 SLAT （二级地址转译，处理器虚拟化技术，为虚拟化应用提供加速功能，如VirtualBox、Hyper-V 等）。
- 在系统 BIOS 中启用硬件虚拟化支持。
- 系统内存至少为 4 GB。
- **Windows：** 64位Windows 10 家庭版、专业版、企业版、教育版、1903 版本或更新版本，并且安装了 Windows 版 Docker 桌面版。
- **macOS：** macOS 版 10.14 或更新版本，并且安装了 Mac 版 Docker 桌面版。
- **Linux：** 64 位版本的 CentOS 7 或更新版本、Debian 10 或更新版本、Fedora 32 或更新版本、Ubuntu 16.04 或更新版本，或任何满足 [Docker 先决条件](https://docs.docker.com/engine/install/binaries/#prerequisites)的 Linux 发行版，并且安装了 Docker 引擎。

 包含在虚幻引擎中的 Windows 容器镜像可以在 Windows 上构建和运行。计算机需满足以下软件要求：

- 64 位 Windows 10 专业版、企业版、教育版、1809 版本或更新并且[安装了 Windows 版 Docker 桌面版](https://docs.docker.com/desktop/windows/install/)。

 推荐使用Docker来构建并运行包含在虚幻引擎中的容器镜像。

 

 5、安装 Docker

**Windows：** [安装 Windows 版 Docker 桌面版](https://docs.docker.com/docker-for-windows/install/)。

  安装时报错：Docker Desktop requires the Server service to be enabled.

  解决：在命令行运行 cmd ，输入命令 services.msc，查找并选中 Server, 将 Server 的服务状态设置为 “启动”。

 

**macOS：** [安装 Mac 版 Docker 桌面版](https://docs.docker.com/docker-for-mac/install/)

**Linux：** 按照相应说明为你的特定Linux发行版安装Docker引擎：[CentOS](https://docs.docker.com/engine/install/centos/)、[Debian](https://docs.docker.com/engine/install/debian/)、[Fedora](https://docs.docker.com/engine/install/fedora/)、[Ubuntu](https://docs.docker.com/engine/install/ubuntu/)、[其他 Linux 发行版](https://docs.docker.com/engine/install/binaries/)。

 

6、使用 Github 容器注册表进行身份验证。

 

Windows 下命令行运行以下：

 

```
>echo ACCESS_TOKEN | docker login ghcr.io -u USERNAME --password-stdin
Login Succeeded
```

`ACCESS_TOKEN` 替换为 GitHub 个人访问令牌;

 

`USERNAME` 替换为 GitHub 用户名;

 

使用以下命令登录 Docker: &gt; docker login

 

使用容器注册表时需要选择 `read:packs` 作用域（下载容器映像并读取其元数据）、 `write:packages` 作用域（下载和上传容器映像并读取和写入其元数据）、`delete:packages` 作用域（删除容器映像）。

否则后续中会出现：

 

```
>docker pull ghcr.io/epicgames/unreal-engine:dev-4.27
Error response from daemon: unauthorized
```

 

 

7、拉取预构建容器镜像

使用以下命令从仓库获取镜像（虚幻引擎 4.27 的 Linux 开发镜像）：

```
>docker pull ghcr.io/epicgames/unreal-engine:dev-4.27
dev-4.27: Pulling from epicgames/unreal-engine
e4ca327ec0e7: Downloading [===>                                               ]  1.948MB/26.71MB
719abd77eec9: Downloading [==============>                                    ]  1.965MB/6.907MB
9df1097c01f2: Download complete
6b384b7c6b03: Download complete
00b95fadb0bd: Downloading [=>                                                 ]  1.614MB/76.96MB
c753ccbd2736: Waiting
5a531cce8e03: Waiting
8bca498ef3ff: Pulling fs layer
c47731c87643: Waiting
d3696f0bbba6: Waiting
df04517ea90f: Waiting
2a22dbd3194e: Waiting
775ef48a05d4: Waiting
d24a8ebc0315: Waiting
aef8bd19d14f: Waiting
93d97caece49: Waiting
4f4fb700ef54: Waiting
36f9989086fc: Waiting
71dd8ab19e1c: Waiting
c68774f47d20: Pulling fs layer
```

 

执行该命令将下载一个封装了虚幻编辑器专用文件和构建工具的容器镜像，该镜像非常大。下载完会提示 "Status：Downloaded newer image for ghcr.io/epicgames/unreal-engine:dev-4.27"。

 

发现下载错了，我需要的是运行时镜像，于是 Ctrl+C 退出，执行以下清理镜像：

 

 

```
>docker image prune
WARNING! This will remove all dangling images.
Are you sure you want to continue? [y/N] y
Total reclaimed space: 0B
```

 

 

重新下载 runtime 镜像：

 

 

```
>docker pull ghcr.io/epicgames/unreal-engine:runtime-pixel-streaming
runtime-pixel-streaming: Pulling from epicgames/unreal-engine
d519e2592276: Waiting
d22d2dfcfa9c: Waiting
b3afe92c540b: Waiting
13a10df09dc1: Waiting
2028b9938ee3: Waiting
7784d5dee6f3: Waiting
787edf8a99c5: Waiting
c48f4acc9130: Waiting
719056f6b70a: Waiting
18ba7c45936e: Waiting
32ec3164a942: Waiting
bdbb5460508f: Waiting
75e6acbb0b6b: Waiting
68a5e2378345: Waiting
c36ee307280f: Pulling fs layer
599293a01162: Waiting
12066cdb74ea: Waiting
```

 

 

还是很慢的。无奈切换了其他镜像。

 

```
>docker pull ghcr.io/epicgames/unreal-engine:runtime-windows-20H2
runtime-windows-20H2: Pulling from epicgames/unreal-engine
18ae6bebe21d: Waiting
df018de09299: Waiting
b00a66660c45: Waiting
40ec84372bd0: Waiting
2a1f1dd9b0e6: Waiting
8f76d0fa8cca: Waiting
93181ca6b4a6: Waiting
image operating system "windows" cannot be used on this platform
```

 

发现没有将 Docker 切换为 windows Container。。。于是右键 “Switch to WIndows Container”。继续弹出以下错误：

 

```
An error occurred：

Containers feature is disabled. Enable it using the PowerShell script (in an administrative PowerShell) and restart your computer before using Docker Desktop: 

Enable-WindowsOptionalFeature -Online -FeatureName $("Microsoft-Hyper-V", "Containers") -All
```

 

解决方式：需要以 administrator 运行 Powershell，然后在 Powershell 中执行：

 

```
>Enable-WindowsOptionalFeature -Online -FeatureName $("Microsoft-Hyper-V", "Containers") -All
```

 

继续运行拉取命令：

 

```
PS C:\Windows\system32> docker pull ghcr.io/epicgames/unreal-engine:runtime-windows-20H2
runtime-windows-20H2: Pulling from epicgames/unreal-engine
18ae6bebe21d: Downloading [==>                                                ]  69.75MB/1.505GB
df018de09299: Downloading [>                                                  ]  3.243MB/1.187GB
b00a66660c45: Downloading [=>                                                 ]  352.1kB/16.51MB
40ec84372bd0: Waiting
2a1f1dd9b0e6: Waiting
8f76d0fa8cca: Waiting
93181ca6b4a6: Waiting
```

 

有速度了。拉取完是这样的：

 

```
PS C:\Windows\system32> docker pull ghcr.io/epicgames/unreal-engine:runtime-windows-20H2
runtime-windows-20H2: Pulling from epicgames/unreal-engine
18ae6bebe21d: Pull complete
df018de09299: Pull complete
b00a66660c45: Pull complete
40ec84372bd0: Pull complete
2a1f1dd9b0e6: Pull complete
8f76d0fa8cca: Pull complete
93181ca6b4a6: Pull complete
Digest: sha256:b8765ded5ffaa97be8c415967b22c3a538098693c457d546d4a065ee03f5803b
Status: Downloaded newer image for ghcr.io/epicgames/unreal-engine:runtime-windows-20H2
ghcr.io/epicgames/unreal-engine:runtime-windows-20H2
PS C:\Windows\system32>
```

 

 

 

8、在运行时容器中运行一个项目

 

 

 

 [UE4 Docker 的未来发展](https://adamrehn.com/articles/preview-the-future-of-ue4-docker/)。