- 两种方案创建容器:step by step创建容器、Dockerfile创建容器
- 创建之后使用scp命令创建之后使用scp命令
方法一:step by step创建容器
# centos7环境下
docker run -it --name=test_container docker.io/centos:7 /bin/bash
# 进入容器输入命令
yum -y install openssh-server openssh-clients iproute
ssh-keygen -q -t rsa -b 2048 -f /etc/ssh/ssh_host_rsa_key -N ''
ssh-keygen -q -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
ssh-keygen -t dsa -f /etc/ssh/ssh_host_ed25519_key -N ''
sed -i "s/#UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config
sed -i "s/UsePAM.*/UsePAM no/g" /etc/ssh/sshd_config
echo 'test_password' | passwd --stdin root
# 退出
exit 退出容器
Ctrl + P + Q 退出容器保持后台运行
#查看container_id
docker ps
docker ps -a
#保存container到镜像test:v1,运行test:v1
docker commit container_id test:v1
docker run -it -p 1234:22 test:v1 /bin/bash
#进入执行
/usr/sbin/sshd -D &
#查看tcp端口
ss -nplt
#关于scp命令使用:
scp -P 1234 lalala.tar root@宿主机hostname:/tmp
方法二:Dockerfile创建容器(ToDo)
#关于scp命令使用:
scp -P 1234 lalala.tar root@宿主机hostname:/tmp