我正在 Docker 容器内设置 Jenkins 主服务器。该容器在 Ubuntu 16.04 主机上运行,该主机本身就是一个虚拟机。
我们在 Jenkins 中使用 NIS 进行身份验证,但是我无法让 NIS 客户端在容器中运行。 在我的 Dockerfile 中我复制了在 Ubuntu 上设置 NIS 的说明:
FROM jenkins
MAINTAINER John McGehee
# The base image set USER to jenkins
USER root
# Change user jenkins uid:pid from 1000:1000 to 7000:7000
RUN groupmod --gid 7000 jenkins
RUN usermod --gid 7000 --uid 7000 jenkins
# Make user jenkins more convenient
RUN mkdir -p /home/jenkins
run chown jenkins:jenkins /home/jenkins
RUN usermod --home /home/jenkins --shell /bin/bash jenkins --comment "Jenkins via Docker"
# Add user jenkins to group shadow so it can use NIS authentication
RUN usermod --groups shadow jenkins
# Set up NIS clients per https://help.ubuntu.com/community/SettingUpNISHowTo
RUN echo '10.10.10.11 infra1 infra1.wavesemi.com infra1.wavecomp.com' >> /etc/hosts
RUN echo '10.10.10.12 infra2 infra2.wavesemi.com infra2.wavecomp.com' >> /etc/hosts
RUN apt-get update
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get install --yes portmap nis
RUN echo 'wavesemi.com' > /etc/defaultdomain
RUN echo 'portmap : 10.10.10.11' >> /etc/hosts.allow
RUN echo 'portmap : 10.10.10.12' >> /etc/hosts.allow
RUN echo '+::::::' >> /etc/passwd
RUN echo '+:::' >> /etc/group
RUN echo '+::::::::' >> /etc/shadow
RUN echo 'ypserver infra1' >> /etc/yp.conf
RUN systemctl start nis
# Run user jenkins in container
USER jenkins
然后我运行了 Dockerfile:
sudo docker build -t myjenkins .
该命令RUN systemctl start nis
给出错误:
Failed to get D-Bus connection: Unknown error -1
The command '/bin/sh -c systemctl start nis' returned a non-zero code: 1
但 Dockerfile 的其余部分运行成功。
当我启动容器时,它只知道用户jenkins
,如容器中所定义的/etc/passwd
。