我在我的ubuntu机器上安装了docker image - centos 7。但是找不到ssh服务。所以我不能运行这项服务。
[root@990e92224a82 /]# yum install openssh-server openssh-clients
Loaded plugins: fastestmirror, ovl
Loading mirror speeds from cached hostfile
* base: mirror.dhakacom.com
* extras: mirror.dhakacom.com
* updates: mirror.dhakacom.com
Package openssh-server-6.6.1p1-31.el7.x86_64 already installed and latest version
Package openssh-clients-6.6.1p1-31.el7.x86_64 already installed and latest version
Nothing to do
[root@990e92224a82 /]# ss
ssh ssh-agent ssh-keygen sshd ssltap
ssh-add ssh-copy-id ssh-keyscan sshd-keygen
如何远程登录泊坞窗图像?
答案 0 :(得分:3)
您必须在Dockerfile上执行以下指示。
RUN yum install -y sudo wget telnet openssh-server vim git ncurses-term
RUN useradd your_account
RUN mkdir -p /home/your_account/.ssh && chown -R your_account /home/your_account/.ssh/
# Create known_hosts
RUN touch /home/your_account/.ssh/known_hosts
COPY files/authorized_keys /home/your_account/.ssh/
COPY files/config /home/your_account/.ssh/
COPY files/pam.d/sshd /etc/pam.d/sshd
RUN touch /home/your_account/.ssh/environment
RUN chown -R your_account /home/your_account/.ssh
RUN chmod 400 -R /home/your_account/.ssh/*
RUN chmod 700 -R /home/your_account/.ssh/known_hosts
RUN chmod 700 /home/your_account/.ssh/environment
# Enable sshd
COPY files/sshd_config /etc/ssh/
RUN ssh-keygen -f /etc/ssh/ssh_host_rsa_key -N '' -t rsa
# Add a account into sudoers and this account doesn't need to type his password
COPY files/sudoers /etc/
COPY files/start.sh /root/
我必须删除" pam_nologin.so"在文件/etc/pam.d/sshd上,因为当我将openssh-server的版本升级到openssh-server-6.6.1p1-31.el7时,pam_nologin.so将禁止任何用户的远程登录文件/ etc / nologin不存在。
start.sh
#!/bin/bash
/usr/sbin/sshd -E /tmp/sshd.log
启动centos容器
登录容器
答案 1 :(得分:1)
扩展到@puritys
您可以在Dockerfile中执行此操作
文件中的最后一行:
ENTRYPOINT /usr/sbin/sshd -E /tmp/sshd.log && /bin/bash
然后你只需要运行:
docker run -d -p -t $(sshPort):22 --name $(containerName) $(imageName) /bin/bash