xshell连接windows10中的docker
先安装centos,不选版本,默认最新版
[C:\~]$ docker pull centos
查看安装的镜像
-
[C:\~]$ docker images
-
REPOSITORY TAG IMAGE ID CREATED SIZE
-
morton/ubuntu dev f2657d57c189 3 months ago 137MB
-
morton/ubuntu v2 f2657d57c189 3 months ago 137MB
-
docker101tutorial latest 25cd022b4be6 3 months ago 27.3MB
-
mortonshaw/docker101tutorial latest 25cd022b4be6 3 months ago 27.3MB
-
ubuntu latest bb0eaf4eee00 3 months ago 72.9MB
-
node 12-alpine 1f52b7199ba6 3 months ago 89.3MB
-
python alpine 0f03316d4a27 3 months ago 42.7MB
-
nginx alpine 6f715d38cfe0 4 months ago 22.1MB
-
centos latest 0d120b6ccaa8 4 months ago 215MB
-
centos centos7.2.1511 9aec5c5fe4ba 21 months ago 195MB
-
ubuntu 15.10 9b9cb95443b5 4 years ago 137MB
-
training/webapp latest 6fae60ef3446 5 years ago 349MB
启动镜像
说明
- -p 端口映射
- --name 指定容器名称
- --privileged=true 打开权限
- /usr/sbin/init 启动systemd服务
其中后两项是必须的,否则不能使用systemctl管理ssh服务
[C:\~]$ docker run -itd -p 50001:22 --name centos_ssl --privileged=true centos /usr/sbin/init
查看容器
-
[C:\~]$ docker ps -a
-
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
-
790d0ff9e176 centos "/usr/sbin/init" 3 minutes ago Up 3 minutes 0.0.0.0:50001->22/tcp centos_ssl
-
00de92573eac centos:centos7.2.1511 "/bin/bash" 3 months ago Exited (137) 2 months ago centos-zabbix
进入容器
[C:\~]$ docker exec -it centos_ssl /bin/bash
安装SSH相关服务
[root@36157c757262 /]# yum install -y openssh*
启动服务
-
[root@36157c757262 /]# systemctl start sshd
-
[root@36157c757262 /]# systemctl enable sshd
-
[root@36157c757262 /]# systemctl status sshd
初始化root用户密码,密码为root
-
[root@36157c757262 /]# yum install -y passwd
-
[root@36157c757262 /]# passwd root
-
Changing password for user root.
-
New password:
-
BAD PASSWORD: The password is shorter than 8 characters
-
Retype new password:
-
passwd: all authentication tokens updated successfully.
xshell连接
和正常连接centos一样,ip写localhost(或本机ip),端口为50001(映射docker中的22端口)
docker容器停止/启动/删除等相关操作
-
[C:\~]$ docker stop centos_ssl
-
[C:\~]$ docker start centos_ssl
-
[C:\~]$ docker rm -f centos_ssl