我創建了一個 docker 檔案并以 root 用戶身份運行它 - 以下是我的 docker 檔案。下面的作業正常,我也可以運行影像。
FROM maven:3.6-jdk-11-slim
WORKDIR /app
COPY . .
RUN mvn clean dependency:go-offline
RUN chmod x run.sh
ENTRYPOINT ["./run.sh"]
我想以非root用戶身份運行它。run.sh如下
mvn clean spring-boot:run
我試圖將 dockerfile 更改為
FROM maven:3.6-jdk-11-slim
WORKDIR /app
COPY . .
RUN mvn clean dependency:go-offline
RUN groupadd -r -g 2000 mygrp && useradd -u 2000 -r -g mygrp myuser
RUN chown -R myuser:mygrp .
RUN chmod -R 700 run.sh
USER myuser
RUN chmod u x run.sh
ENTRYPOINT ["./run.sh"]
影像構建良好,但是當我嘗試運行時 - 這是錯誤
[ERROR] Could not create local repository at /home/myuser/.m2/repository -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/LocalRepositoryNotAccessibleException
uj5u.com熱心網友回復:
您可能需要更新groupadd說明。
代替:
RUN groupadd -r -g 2000 mygrp && useradd -u 2000 -r -g mygrp myuser
在 Dockerfile 中有這個:
RUN groupadd -r -g 2000 mygrp && useradd -m -d /home/myuser/ -s /bin/bash -u 2000 -r -g mygrp myuser
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/490765.html
