xshell连接windows10中的docker

先安装centos,不选版本,默认最新版

[C:\~]$ docker pull centos
 

查看安装的镜像

  1.  
    [C:\~]$ docker images
  2.  
    REPOSITORY TAG IMAGE ID CREATED SIZE
  3.  
    morton/ubuntu dev f2657d57c189 3 months ago 137MB
  4.  
    morton/ubuntu v2 f2657d57c189 3 months ago 137MB
  5.  
    docker101tutorial latest 25cd022b4be6 3 months ago 27.3MB
  6.  
    mortonshaw/docker101tutorial latest 25cd022b4be6 3 months ago 27.3MB
  7.  
    ubuntu latest bb0eaf4eee00 3 months ago 72.9MB
  8.  
    node 12-alpine 1f52b7199ba6 3 months ago 89.3MB
  9.  
    python alpine 0f03316d4a27 3 months ago 42.7MB
  10.  
    nginx alpine 6f715d38cfe0 4 months ago 22.1MB
  11.  
    centos latest 0d120b6ccaa8 4 months ago 215MB
  12.  
    centos centos7.2.1511 9aec5c5fe4ba 21 months ago 195MB
  13.  
    ubuntu 15.10 9b9cb95443b5 4 years ago 137MB
  14.  
    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
 

查看容器

  1.  
    [C:\~]$ docker ps -a
  2.  
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3.  
    790d0ff9e176 centos "/usr/sbin/init" 3 minutes ago Up 3 minutes 0.0.0.0:50001->22/tcp centos_ssl
  4.  
    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*
 

启动服务

  1.  
    [root@36157c757262 /]# systemctl start sshd
  2.  
    [root@36157c757262 /]# systemctl enable sshd
  3.  
    [root@36157c757262 /]# systemctl status sshd

初始化root用户密码,密码为root

  1.  
    [root@36157c757262 /]# yum install -y passwd
  2.  
    [root@36157c757262 /]# passwd root
  3.  
    Changing password for user root.
  4.  
    New password:
  5.  
    BAD PASSWORD: The password is shorter than 8 characters
  6.  
    Retype new password:
  7.  
    passwd: all authentication tokens updated successfully.

xshell连接

和正常连接centos一样,ip写localhost(或本机ip),端口为50001(映射docker中的22端口)

docker容器停止/启动/删除等相关操作

  1.  
    [C:\~]$ docker stop centos_ssl
  2.  
    [C:\~]$ docker start centos_ssl
  3.  
    [C:\~]$ docker rm -f centos_ssl

 

 
posted @ 2022-07-07 19:02  快乐的在一起  阅读(369)  评论(0编辑  收藏  举报