イメージを構築し、コンテナーをsshサーバーとして実行しようとしています。そのコンテナ(remote_host)を別のコンテナ(jenkins / jenkins)からsshできるようにしたい
CentosでVMを使用しています。
このdockerファイルを使用しています。VMホストマシンから実行します(Centosも)
FROM centos
RUN yum -y install openssh-server openssh-clients
RUN useradd -ms /bin/bash remote_user && \
echo 'remote_user:12345' | chpasswd && \
mkdir /home/remote_user/.ssh && \
chmod 700 /home/remote_user/.ssh
COPY remote-key.pub /home/remote_user/.ssh/authorized_keys
RUN chown remote_user:remote_user -R /home/remote_user/.ssh && \
chmod 600 /home/remote_user/.ssh/authorized_keys
EXPOSE 22
RUN /usr/bin/ssh-keygen -A
CMD ["/usr/sbin/sshd", "-D"]
Docker作成ファイル
---
networks:
net: ~
services:
jenkins:
container_name: jenkins
image: jenkins/jenkins
networks:
- net
ports:
- "8080:8080"
volumes:
- "$PWD/jenkins_home:/var/jenkins_home"
remote_host:
container_name: remote-host
image: remote-host
build:
context: centos7
networks:
- net
version: "3"
docker-compose build
ホストマシンから実行します
Building remote_host
Step 1/8 : FROM centos
---> 0f3e07c0138f
Step 2/8 : RUN yum -y install openssh-server openssh-clients
---> Using cache
---> 277411f7cc41
Step 3/8 : RUN useradd -ms /bin/bash remote_user && echo 'remote_user:12345' | chpasswd && mkdir /home/remote_user/.ssh && chmod 700 /home/remote_user/.ssh
---> Using cache
---> c42b15de9da7
Step 4/8 : COPY remote-key.pub /home/remote_user/.ssh/authorized_keys
---> Using cache
---> f205521e83cb
Step 5/8 : RUN chown remote_user:remote_user -R /home/remote_user/.ssh && chmod 600 /home/remote_user/.ssh/authorized_keys
---> Using cache
---> a7bb438b87ed
Step 6/8 : EXPOSE 22
---> Using cache
---> 7f28ef8e4ec9
Step 7/8 : RUN /usr/bin/ssh-keygen -A
---> Using cache
---> a4fae9730627
Step 8/8 : CMD ["/usr/sbin/sshd", "-D"]
---> Using cache
---> 3fe69c9789a6
Successfully built 3fe69c9789a6
Successfully tagged remote-host:latest
それから私は走ります docker-compose up -d
docker psは私に与えます:
0f9987444fcf remote-host "/usr/sbin/sshd -D" 28 minutes ago Up 16 minutes 22/tcp remote-host
4c9ba830f419 jenkins/jenkins "/sbin/tini -- /usr/…" 7 hours ago Up 7 hours 0.0.0.0:8080->8080/tcp, 50000/tcp jenkins
私は最初のコンテナをsshします:
docker exec -it jenkins bash
次に、最初のコンテナから2番目のコンテナをsshしようとすると
ssh remote_user@remote_host
このエラーが発生しました
Are you sure you want to continue connecting (yes/no)?
remote_user@remote_host's password:12345
"System is booting up. Unprivileged users are not permitted to log in yet. Please come back later. For technical details, see pam_nologin(8)."
Authentication failed.
解決:
次のようにdockerfileを編集してください。
FROM centos
RUN yum -y install openssh-server
RUN useradd remote_user && \
echo remote_user:1234 | chpasswd && \
mkdir /home/remote_user/.ssh && \
chmod 700 /home/remote_user/.ssh
COPY remote-key.pub /home/remote_user/.ssh/authorized_keys
RUN chown remote_user:remote_user -R /home/remote_user/.ssh && \
chmod 600 /home/remote_user/.ssh/authorized_keys
RUN /usr/bin/ssh-keygen -A
EXPOSE 22
RUN rm -rf /run/nologin
CMD /usr/sbin/sshd -D
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加