docker - Apache 用户从 openshift 构建中的图像中删除 - whoami 错误
问题描述
我一直在将一个项目从 kube 转移到 openshift。在 minikube 中,该项目运行良好,但在 minishift 中,它给出了错误
— Crash loop back off
这是来自 minishift 日志
[WARN] $TIMEZONE not set.
[INFO] Docker date set to: Tue Apr 20 17:39:02 UTC 2021
[INFO] $PHP_FPM_ENABLE not set. PHP-FPM support disabled.
[INFO] $CUSTOM_HTTPD_CONF_DIR not set. No custom include directory added.
[INFO] Starting Server version: Apache/2.2.15 (Unix)
whoami: cannot find name for user ID 1000140000
这是相关的deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.22.0 (HEAD)
creationTimestamp: null
labels:
io.kompose.service: occtool
name: occtool
spec:
replicas: 1
selector:
matchLabels:
io.kompose.service: occtool
strategy: {}
template:
metadata:
annotations:
kompose.cmd: kompose convert
kompose.version: 1.22.0 (HEAD)
creationTimestamp: null
labels:
io.kompose.network/backend: "true"
io.kompose.network/frontend: "true"
io.kompose.service: occtool
spec:
containers:
- image: private.registry.com/image:tag
imagePullPolicy: IfNotPresent
name: occtool
ports:
- containerPort: 80
- containerPort: 443
resources: {}
restartPolicy: Always
status: {}
这是 Dockerfile
FROM cytopia/apache-2.2:0.9
# lines that copied files were omitted for convenience
USER root
我没有找到太多相关信息。 USER root
最初已被省略,因此用户是 apache。使用 minishift ssh 和 docker exec 我注意到用户 apache 在 pod 中不存在,但是在构建映像时我无法运行命令来创建用户,因为用户确实存在于映像中。我相信这是问题的根源,但是我还没有找到在openshift中创建用户的方法,也不知道为什么在构建pod时会删除用户。
解决方案
OpenShift 忽略USER
来自 Dockerfiles 的 -directive,而是为容器中的用户生成一个随机 UID。这背后有一些关于安全的想法。
来自 OpenShift文档:
支持任意用户 ID
默认情况下,OpenShift Container Platform 使用任意分配的用户 ID 运行容器。这为由于容器引擎漏洞而逃离容器的进程提供了额外的安全性,从而在主机节点上实现了升级的权限。
对于支持以任意用户身份运行的映像,映像中的进程可能写入的目录和文件应归根组所有,并且可由该组读取/写入。要执行的文件也应该具有组执行权限。
推荐阅读
- python - 有没有办法将特定消息发送到与 python 不一致的特定服务器和通道?
- python - Python 什么时候真正向服务器发出请求?
- mysql - 使用 ssh 创建 MySQL 用户
- python - Selenium:如果包含',XPATH 会中断
- r - R:crosstalk::SharedData 以不同格式(宽/长)链接数据,当 tidyverse 动词不起作用时
- linux - bash:在最后一个分隔符之前剪切特定字符串
- c# - 如何在屏幕上查找特定文本及其位置?C#
- python - Python中的类和静态方法有什么区别,因为在静态方法中,您可以通过名称而不是cls来访问类?
- vba - 用户登录后无法加载表单
- github - 如何在 Github 中合并具有完全不同提交历史的分支?