ubuntu 创建容器 并ssh 连接容器

1.下载镜像:docker search ubuntu 

docker pull ubuntu

2. 创建容器

docker run --name spider_frame -p 8888:8888 -p 10023:22 -it -d python:3.7 /bin/bash

3.进入容器docker exec -it spider_frame /bin/bash

4. 安装:

安装容器的openssh-server,输入 apt-get install openssh-server -y

5.

成功安装后,vim /etc/ssh/sshd_config,修改下面两个配置

PermitRootLogin yes  
UsePAM no

6.

  1. 启动ssh服务,service ssh start

  2. 退出容器,输入exit,然后输入docker ps -a,查看容器的ID

  3. 提交容器成为新的镜像,例如叫做ubuntu-ssh,输入docker commit 容器ID ubuntu-ssh

 7.设置ssh密码:$ passwd root


Enter new UNIX password: 
Retype new UNIX password: 
passwd: password updated successfully

参考资料:https://blog.csdn.net/ypbsyy/article/details/80529101

https://blog.csdn.net/u010324465/article/details/77184506

原文地址:https://www.cnblogs.com/myvic/p/10723933.html