docker pull centos:7
docker run -d --name ssh_box --privileged=true centos:7 /usr/sbin/init
07228ec257564c4874ca24216d651bda65573d49e4149064a079cacca27de4e1 # 生成的容器ID
--name 给新生成的容器命名
--privileged=true 给容器访问Linux内核特权,后面要访问systemctl
返回一串容器ID表示容器生成成功
3. 进入刚刚生成的容器
docker exec -it 07228ec25756 /bin/bash
4.安装vim和Openssh(docker 容器中执行)
yum install vim openssh-server openssh-clients -y
5.修改SSH配置文件
?vim /etc/ssh/sshd_config
PubkeyAuthentication yes #启用公钥私钥配对认证方式
AuthorizedKeysFile .ssh/authorized_keys #公钥文件路径(和上面生成的文件同)
PermitRootLogin yes #root能使用ssh登录
ClientAliveInterval 60 #参数数值是秒 , 是指超时时间
ClientAliveCountMax 3 #设置允许超时的次数
-m:来指定提交的说明信息,跟我们使用的版本控制工具一样
-a?可以指定更新的用户信息
ffe81683c404: 创建镜像的容器的ID,就是上面的容器id,也就是我们刚才进入的容器id
ssh_box: 目标镜像的仓库名
docker images可以查看到新生成的镜像
10.然后可以使用xshell连接新生成的容器
ip: 为宿主主机的ip,而不是docker容器的ip
端口:就是上面的2222
用户名: root
密码: 就是上面password部分设置的密码
在mac上可通过ssh root@ip -p:2222 登录新生成的容器
Docker容器使用问题:Failed to get D-Bus connection: Operation not permitted
ssh 直接登录docker容器
原文:https://www.cnblogs.com/jesse131/p/13543308.html