gpt4 book ai didi

docker - 使用 postgres 和 java 构建 docker

转载 作者:行者123 更新时间:2023-12-04 19:42:26 25 4
gpt4 key购买 nike

我想扩展 docker ( postgresql-96-centos7 ) 以添加 java.util.
我尝试构建下一个 dockerfile:

FROM centos/postgresql-96-centos7

RUN yum update -y && \
yum install -y wget && \
yum install -y java-1.8.0-openjdk && \
yum clean all

# Set environment variables.
ENV HOME /root

# Define working directory.
WORKDIR /root

# Define default command.
CMD ["bash"]

用命令:
docker image build -t centos_pgs_java .

但是有一个错误:
Step 3/6 : RUN yum update -y && yum install -y wget && yum install -y java-1.8.0-openjdk && yum clean all
---> Running in d93a94a61a11
Loaded plugins: fastestmirror, ovl
ovl: Error while doing RPMdb copy-up:
[Errno 13] Permission denied: '/var/lib/rpm/Group'
You need to be root to perform this command.
The command '/bin/sh -c yum update -y && yum install -y wget && yum install -y java-1.8.0-openjdk && yum clean all' returned a non-zero code: 1

如何在具有 root 访问权限的 dockerfile 中重写 RUN 命令?

最佳答案

根据Dockerfile文档:

The USER instruction sets the user name (or UID) and optionally the user group (or GID) to use when running the image and for any RUN, CMD and ENTRYPOINT instructions that follow it in the Dockerfile.



因此,您需要将用户更改为 root ,执行 RUN 层并将用户返回到 26正如它在 centos/postgresql-96-centos7 中定义的那样 docker 形象。

决赛 Dockerfile是:
FROM centos/postgresql-96-centos7

USER root

RUN yum update -y && \
yum install -y wget && \
yum install -y java-1.8.0-openjdk && \
yum clean all

USER 26

# Set environment variables.
ENV HOME /root

# Define working directory.
WORKDIR /root

# Define default command.
CMD ["bash"]

关于docker - 使用 postgres 和 java 构建 docker,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51385782/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com