1、启动一个docker容器
# docker run -t -i ubuntu/ruby:v1 /bin/bash
2、然后在容器里,安装openssh-server openssh-client
# apt-get install openssh-server openssh-client
3、完成之后,修改root密码
# passwd
4、退出容器,并保存以上修改
# docker commit 3ea7a99a0025 ubuntu/ruby:v2
5、停止,并删除刚才的容器
# docker stop [container-id]
# docker rm [container-id]
查看容器id
# docker ps -a
查看镜像列表
# docker p_w_picpaths
6、用刚保存的镜像,后台启动一个新的容器
docker run --name [p_w_picpath-name] -i -t -p 50001:22 [p_w_picpath-id]
例: # docker run -d -p 50001:22 ubuntu/ruby:v2 /usr/sbin/sshd -D
7、ssh远程登录该容器
# ssh root@localhost -p 50001
如果想要通过ssh密钥登录,则在第2步,修改 /etc/ssh/sshd_config 文件,将RSAAuthentication 和 PubkeyAuthentication 后面的值都改成yes ,保存。
将本地.ssh下的id_rsa.pub上传到容器中的 id_rsa.pub,并 # mv /root/.ssh/id_rsa.pub/root/.ssh/authorized_keys,然后 # chmod 600 /root/.ssh/authorized_keys 即可.
ssh登录docker容器
原创yzy121403725 博主文章分类:docker学习 ©著作权
文章标签 docker ssh 文章分类 Docker 云计算
-
Docker修改容器的时间
Docker容器内系统时间不准确,可能会导致一系列问题,尤其是在依赖于时间戳进行操作的应用和服务中。
系统时间 Docker 时间同步 后端 服务器