当前位置: 首页 > news >正文

构建可以ssh连接的容器镜像

构建可以ssh连接的容器镜像

构建可以通过ssh进行连接容器镜像,实现远程登录容器的目的。

ubuntu ssh容器镜像

你可以使用以下Dockerfile来构建一个可以SSH的容器镜像:

FROM ubuntu:20.04MAINTAINER lldhsds# 配置apt国内源
COPY sources.list /etc/apt/# 安装OpenSSH Server
RUN apt-get update && apt-get install -y openssh-server# 创建SSH服务的必要目录
RUN mkdir /var/run/sshd# 设置root用户的密码
RUN echo 'root:ubuntu' | chpasswd# 允许root用户通过SSH登录
RUN sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config# 暴露SSH端口
EXPOSE 22# 启动SSH服务
CMD ["/usr/sbin/sshd", "-D"]

在dockerfile同目录下,创建镜像源文件sources.list,内容如下:

deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
# deb http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src http://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

使用以下命令构建和运行镜像:

docker build -t ubuntu-ssh .
docker run -d -p 2222:22 ubuntu-ssh

然后,你可以通过SSH连接到容器:

ssh root@localhost -p 2222

centos ssh容器镜像

可以使用以下Dockerfile来构建一个可以SSH的容器镜像:

FROM centos:7MAINTAINER lldhsdsRUN rm -rf /etc/yum.repos.d/*ADD repo.tar.gz /etc/yum.repos.d/RUN yum install openssh-clients openssh-server -y && \ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key && \ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key && \ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key && \sed -i 's/#UseDNS yes/UseDNS no/' /etc/ssh/sshd_config && \echo "root:centos"| chpasswdEXPOSE 22CMD ["/usr/sbin/sshd", "-D"]

根据需要调整密码和配置!

dockerfile同目录下,创建repo.tar.gz,内容如下:

tar zcvf repo.tar.gz centos7.repo

其中cenos7.repo内容如下:

[base]
name=CentOS-$releasever - Base - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#released updates
[updates]
name=CentOS-$releasever - Updates - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#additional packages that may be useful
[extras]
name=CentOS-$releasever - Extras - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
gpgcheck=1
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-$releasever - Plus - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7#contrib - packages by Centos Users
[contrib]
name=CentOS-$releasever - Contrib - mirrors.aliyun.com
failovermethod=priority
baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirrors.aliyun.com/centos/RPM-GPG-KEY-CentOS-7
http://www.lryc.cn/news/458391.html

相关文章:

  • 数据库中JOIN的用法?
  • java项目之纺织品企业财务管理系统源码(springboot+vue+mysql)
  • C语言 编程练习:解决五个有趣的问题
  • 二、安装vmtools
  • 用echarts画天气预报
  • 如果要存IP地址,用什么数据类型比较好?(java)
  • LinkedList源码解读
  • springboot feign-httpclient 连接池配置
  • 电汽车充电革命:充电桩的过去现在与未来
  • windows server 2019中安装.net framework 3.5功能出错
  • vscode gitlens收费破解
  • IPv 4
  • SQL 注入漏洞 - 学习手册
  • AVLTree 旋转笔记(根据平衡因子插入的公式,贼好理解)
  • STM32(十八):SPI通信
  • Redis持久化机制(RDBAOF详解)
  • 蛋白质结构中pdbx_strand_id和entity_id相互转化
  • 【父子线程传值TransmittableThreadLocal使用踩坑-及相关知识拓展】
  • 03 快乐树
  • springboot+react实现移动端相册(上传图片到oss/ 批量删除/ 查看图片详情等功能)
  • Python、R语言Lasso、Ridge岭回归、XGBoost分析Airbnb房屋数据:旅游市场差异、价格预测|数据分享...
  • Spring Boot驱动的交互式作业管理系统:师生共评功能实现
  • 基于SSM的旅游网站【附源码】
  • Python实现将目标文本批量存入Word,并将文本段落的开头进行缩进处理(11)
  • el-select 下拉框选项文字过长解决方案
  • C语言基础语法——类型转换
  • 来电无通话界面问题分析
  • 物理学基础精解【70】
  • HCIP--以太网交换安全(三)MAC地址漂移防止与检测
  • CSS3--美若天仙!?