用postgres和java构建docker

时间:2018-07-17 15:59:18

标签: docker centos

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

error   17-Jul-2018 18:44:45    18:44:45.846 WARN: [/home/myuser/server/RequestHandler.h:5]: cannot find the sources for '#include <string>'
error   17-Jul-2018 18:44:45    18:44:45.847 WARN: [/home/myuser/server/RequestHandler.h:6]: cannot find the sources for '#include <iostream>'
error   17-Jul-2018 18:44:45    18:44:45.847 WARN: [/home/myuser/server/RequestHandler.h:7]: cannot find the sources for '#include <algorithm>'
error   17-Jul-2018 18:44:45    18:44:45.847 WARN: [/home/myuser/server/RequestHandler.h:8]: cannot find the sources for '#include <memory>'

使用命令:

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 .

如何用root用户权限重写dockerfile中的RUN命令?

1 个答案:

答案 0 :(得分:0)

根据Dockerfile文档:

  

USER指令设置用户名(或UID),并可选地设置   运行映像以及任何RUN,CMD时要使用的用户组(或GID)   以及Dockerfile中紧随其后的ENTRYPOINT指令。

因此,您需要将用户更改为root,执行RUN层,并将用户返回到26码头工人镜像中定义的centos/postgresql-96-centos7

最后的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"]
相关问题