示例 - CentOS7

[root@CentOS-7 ~]# cat ssh-centos7
FROM centos:centos7
MAINTAINER anliven "anliven@yeah.net"  
ENV http_proxy="http://10.144.1.10:8080"
RUN yum install -y openssh-server \
&& yum install -y inetutils-ping iproute net-tools \
&& yum clean all \
&& echo '123456' | passwd --stdin root \
&& ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key \
&& ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# docker build --file ssh-centos7 --tag ssh:centos7 .
Sending build context to Docker daemon 18.55 MB
Step 1 : FROM centos:centos7
---> a8493f5f50ff
Step 2 : MAINTAINER anliven "anliven@yeah.net"
---> Running in 204f723fabdd
---> 89fa55e17d5f
Removing intermediate container 204f723fabdd
Step 3 : ENV http_proxy "http://10.144.1.10:8080"
---> Running in 2f70b94e0d63
---> 0e50b2cfdc9e
Removing intermediate container 2f70b94e0d63
Step 4 : RUN yum install -y openssh-server && yum install -y inetutils-ping iproute net-tools && yum clean all && echo '123456' | passwd --stdin root && ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key && ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
---> Running in fb4b2380f5ec
......
......
......
---> d1548e06d027
Removing intermediate container fb4b2380f5ec
Step 5 : EXPOSE 22
---> Running in 03afbb7ffc45
---> 90c69174857b
Removing intermediate container 03afbb7ffc45
Step 6 : CMD /usr/sbin/sshd -D
---> Running in a07326dc62aa
---> 3bf6495f5de6
Removing intermediate container a07326dc62aa
Successfully built 3bf6495f5de6
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# docker images ssh:centos7
REPOSITORY TAG IMAGE ID CREATED SIZE
ssh centos7 3bf6495f5de6 About a minute ago 217.9 MB
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# docker run -d -P ssh:centos7
1733db18cfd18735504272f90655d832b36e898998e5054bbbf499fcab381827
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1733db18cfd1 ssh:centos7 "/usr/sbin/sshd -D" 7 seconds ago Up 6 seconds 0.0.0.0:32769->22/tcp amazing_hamilton
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# ssh -p 32769 root@0.0.0.0
The authenticity of host '[0.0.0.0]:32769 ([0.0.0.0]:32769)' can't be established.
RSA key fingerprint is cf:28:2c:32:94:82:40:2a:b3:54:51:6f:f6:0b:43:e8.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[0.0.0.0]:32769' (RSA) to the list of known hosts.
root@0.0.0.0's password:
[root@1733db18cfd1 ~]#
[root@1733db18cfd1 ~]# ip addr show |grep eth0
52: eth0@if53: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP
inet 172.17.0.2/16 scope global eth0
[root@1733db18cfd1 ~]#
[root@1733db18cfd1 ~]# exit
logout
Connection to 0.0.0.0 closed.
[root@CentOS-7 ~]#

示例 - Ubuntu16.04

[root@CentOS-7 ~]# cat ssh-ubuntu16
FROM ubuntu:16.04
MAINTAINER anliven "anliven@yeah.net"
ENV http_proxy="http://10.144.1.10:8080"
RUN apt-get update \
&& apt-get install -y openssh-server \
&& apt-get install -y inetutils-ping iproute net-tools \
&& apt-get clean \
&& mkdir /var/run/sshd \
&& sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config \
&& echo "root:123456" | chpasswd
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# docker build --file ssh-ubuntu16 --tag ssh:ubuntu16 .
Sending build context to Docker daemon 18.55 MB
Step 1 : FROM ubuntu:16.04
---> f7b3f317ec73
Step 2 : MAINTAINER anliven "anliven@yeah.net"
---> Running in 6259dee07753
---> 427750397620
Removing intermediate container 6259dee07753
Step 3 : ENV http_proxy "http://10.144.1.10:8080"
---> Running in bcb0bd688544
---> aa313abb23c8
Removing intermediate container bcb0bd688544
Step 4 : RUN apt-get update && apt-get install -y openssh-server && apt-get install -y inetutils-ping iproute net-tools && apt-get clean && mkdir /var/run/sshd && sed -i 's/PermitRootLogin prohibit-password/PermitRootLogin yes/g' /etc/ssh/sshd_config && echo "root:123456" | chpasswd
---> Running in a916fc8fc699
......
......
......
---> fee74bafa989
Removing intermediate container a916fc8fc699
Step 5 : EXPOSE 22
---> Running in c6d1032bd372
---> a99434e93cc6
Removing intermediate container c6d1032bd372
Step 6 : CMD /usr/sbin/sshd -D
---> Running in 4750dcb341a6
---> c5cbd98fb8c7
Removing intermediate container 4750dcb341a6
Successfully built c5cbd98fb8c7
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# docker images ssh:ubuntu16
REPOSITORY TAG IMAGE ID CREATED SIZE
ssh ubuntu16 c5cbd98fb8c7 47 seconds ago 215.6 MB
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# docker run -d -P ssh:ubuntu16
f92e3274421f3b0dfca0605bc0c8df3ea13dcace3a307e77f4d600f819645537
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f92e3274421f ssh:ubuntu16 "/usr/sbin/sshd -D" 5 seconds ago Up 4 seconds 0.0.0.0:32773->22/tcp dreamy_brahmagupta
[root@CentOS-7 ~]#
[root@CentOS-7 ~]# ssh -p 32773 root@0.0.0.0
The authenticity of host '[0.0.0.0]:32773 ([0.0.0.0]:32773)' can't be established.
ECDSA key fingerprint is 01:66:ff:54:44:34:92:ab:6d:7a:77:a9:6a:18:7d:1d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[0.0.0.0]:32773' (ECDSA) to the list of known hosts.
root@0.0.0.0's password:
Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 3.10.0-327.el7.x86_64 x86_64) * Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law. root@f92e3274421f:~#
root@f92e3274421f:~# exit
logout
Connection to 0.0.0.0 closed.
[root@CentOS-7 ~]#

Docker- 创建支持SSH服务的容器镜像的更多相关文章

  1. Docker创建支持ssh服务的容器和镜像

    原文链接:Docker创建支持ssh服务的容器和镜像 1. 这里使用的centos作为容器,所以首先下载centos的images # sudo docker pull centos 2. 下载后执行 ...

  2. 创建支持ssh服务的docker容器和镜像

    http://www.kongxx.info/blog/?p=57 1. 这里使用的centos作为容器,所以首先下载centos的imagessudo docker pull centos 2. 下 ...

  3. Docker使用Dockerfile创建支持ssh服务自启动的容器镜像

    原文链接:Docker使用Dockerfile创建支持ssh服务自启动的容器镜像 1. 首先创建一个Dockerfile文件.文件内容例如以下 # 选择一个已有的os镜像作为基础 FROM cento ...

  4. Centos7创建支持ssh服务的docker镜像

    如何在centos7中使用docker创建一个支持ssh连接的容器 1.拉取centos7.4镜像(由于7.4目前是最稳定的版本,所以推荐使用centos7.4) docker pull centos ...

  5. 使用Dockerfile创建支持SSH服务的镜像

    1.前面我们学习了使用Dockerfile,那接下来我们就用Dockerfile创建一个支持SSH服务的镜像. 2.首先创建一个目录ssh_centos [root@rocketmq-nameserv ...

  6. docker如何创建支持SSH服务的镜像

    一般情况下,Linux系统管理员通过SSH服务来管理操作系统,但Docker的很多镜像是不带SSH服务的,那么我们怎样才能管理操作系统呢?在第一部分中我们介绍了一些进入容器的办法,比如用attach. ...

  7. Docker(2):使用Dockerfile创建支持SSH服务的镜像

    1.创建工作目录 # mkdir sshd_ubuntu # ls 在其中,创建Dockerfile和run.sh文件 # cd sshd_ubuntu/ # touch Dockerfile run ...

  8. 两种方式创建支持SSH服务的docker镜像

    方法一:基于commit命令创建 1.首先,从docker的源中查看我们需要的镜像,本案例中使用Ubuntu作为基础镜像. # federico @ linux in ~ [16:57:38] $ s ...

  9. docker基于commit命令创建支持ssh服务的镜像

    以centos为基础,目的使用ssh服务远程连接docker容器. 环境:宿主机centos7(宿主机ip地址为192.168.164.130),直接搜索docker的centos镜像,下载最新版本. ...

随机推荐

  1. [译]Selenium Python文档:六、页面对象

    本章是介绍页面对象设计模式的教程.一个页面对象代表了web应用用户接口的一片区域,你的测试代码将与之交互的. 使用页面对象模式的好处: 可以创建在多个测试样例中都可使用的可重用代码 减少重复性代码 如 ...

  2. 编写PHP代码总结

    1- 编写模块化代码 良好的PHP代码应该是模块化代码.PHP的面向对象的编程功能是一些特别强大的工 具,可以把你的应用程序分解成函数或方法.你应该尽可能多的从你的应用程序的服务器端分开前端的HTML ...

  3. javascript 类型的判断

    在平常写js代码,类型判断必不可少,那么我们常见有哪几种?看到了标题,先不看你会想到那些方法 ,常用呢些呢?那么今天我自己总结一些判断类型的判断,如有错,万望告知! 1:typeof 常用这种方法不错 ...

  4. iOS关于友盟分享弹不出面板问题

    在程序代理类中声明 [NSThread sleepForTimeInterval:10];//设置启动页面时间 [self.window makeKeyAndVisible]; [[UMSocialM ...

  5. Hadoop/Spark开发环境配置

    修改hostname bogon 为localhost 查看ip地址 [training@bogon ~]$ sudo hostname localhost [training@bogon ~]$ h ...

  6. 分享一个低配VPS下运行的mysql配置文件

    在各种内存CPU核心只有1/2核,内存只有512M/1G的vps下,内存.CPU.硬盘都不是太充裕.因此主要思路是,禁止吃内存大户innodb引擎,默认使用MyISAM.禁止吃硬盘大户log-bin, ...

  7. NPM(Node.js) 使用介绍

    前言:express 推出了4.X,自己尝试了一下,出现了各种问题.结果查看了各种文档和问题,现在在这个给大家分享下4.X版本的安装. NPM 使用介绍 NPM是随同NodeJS一起安装的包管理工具, ...

  8. Hibernate(四)之对象状态及一级缓存

    一.Hibernate中的对象状态 1.1.瞬时态(临时态) 没有与Hibernate产生关联 与数据库中的记录没有产生关联(有关联就是与数据库中表的id相对应) 获得:一般都只直接创建(new) 瞬 ...

  9. JavaScript 函数的定义-调用、注意事项

    函数定义 函数语句定义 function(a,b){ return a+b; } 表达式定义 var add = function(a,b){return a+b}; //函数表达式可以包含名称,这在 ...

  10. node.js 中模块的循环调用问题详解

    首先,我们看一下图示代码,每一个注释其实代表一个 js 文件.所以下面其实是三个 js 文件 .第一个是我们要运行的 main 文件,后面两个是 a, b 文件.   从上面可以看书 a ,b 两个模 ...