【问题标题】:build docker with postgres and java使用 postgres 和 java 构建 docker
【发布时间】:2018-07-18 00:12:10
【问题描述】:

我想扩展 docker (postgresql-96-centos7) 来添加 java。 我尝试构建下一个 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命令?

【问题讨论】:

  • ...为什么在数据库容器中需要 JVM?

标签: docker centos


【解决方案1】:

根据Dockerfile 文档:

USER 指令设置用户名(或 UID)和可选的 运行映像和任何 RUN、CMD 时使用的用户组(或 GID) 以及 Dockerfile 中的 ENTRYPOINT 指令。

因此,您需要将用户更改为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"]

【讨论】:

  • 感谢您的回复。镜像构建成功但出现警告:
  • 您收到的警告是什么?它似乎被一些格式问题所隐藏。
猜你喜欢
  • 1970-01-01
  • 2016-04-17
  • 2018-06-14
  • 1970-01-01
  • 1970-01-01
  • 2019-07-05
  • 1970-01-01
  • 1970-01-01
  • 2019-03-11
相关资源
最近更新 更多