我正在運行 K8s 部署并試圖加強我的一個 pod 的安全性,因此我開始使用以下 docker 映像:
nginxinc/nginx-unprivileged:alpine
問題是我需要創建一個符號鏈接并且無法完成它。
這是我的dockerfile的結構
FROM nginxinc/nginx-unprivileged:alpine
ARG name
ARG ver
USER root
COPY ./outbox/${name}-${ver}.tgz ./
COPY ./nginx.conf /etc/nginx/nginx.conf
COPY ./mime.types /etc/nginx/mime.types
COPY ./about.md ./
RUN mv /${name}-${ver}.tgz /usr/share/nginx/html
WORKDIR /usr/share/nginx/html
RUN tar -zxf ${name}-${ver}.tgz \
&& mv ngdist/* . \
&& mv /about.md ./assets \
&& rm -fr ngdist web-ui-${ver}.tgz \
&& mkdir -p /tmp/reports
RUN chown -R 1001 /usr/share/nginx/html/
COPY ./entrypoint.sh.${name} /bin/entrypoint.sh
RUN chown 1001 /bin/entrypoint.sh
USER 1001
EXPOSE 8080
CMD [ "/bin/entrypoint.sh" ]
這里是我的 entrypoint.sh
#!/bin/sh
ln -s /tmp/reports /usr/share/nginx/html/reports
這是我在 pod 部署 yaml 檔案中的容器
containers:
- name: web-ui
image: "myimage"
imagePullPolicy: Always
ports:
- containerPort: 8080
name: web-ui
volumeMounts:
- name: myvolume
mountPath: /tmp/reports
我試圖在根執行下設定入口點,但這也沒有幫助,我得到的錯誤是:
錯誤:無法啟動容器“web-ui”:來自守護行程的錯誤回應:OCI 運行時創建失敗:container_linux.go:380:啟動容器行程導致:exec:“/bin/entrypoint.sh”:權限被拒絕:未知
uj5u.com熱心網友回復:
與其他 Linux 命令一樣,如果 Docker 容器的主程式CMD命名的程式不可執行,它就無法運行。
大多數源代碼控制系統將跟蹤檔案是否可執行,并且 DockerCOPY將保留該權限位。所以解決這個問題的最好方法是使腳本在主機上可執行:
chmod x entrypoint.sh.*
git add entrypoint.sh.*
git commit -m 'make entrypoint scripts executable'
docker-compose build
docker-compose up -d
如果這不是一個選項,您也可以在 Dockerfile 中修復它。
COPY ./entrypoint.sh.${name} /bin/entrypoint.sh
RUN chmod 0755 /bin/entrypoint.sh
與 中的其他內容一樣/bin,腳本通常應該由 root 擁有,每個人都可以執行,并且只能由其所有者寫入;您通常不希望應用程式能夠覆寫自己的代碼。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/457926.html
