参考:https://docs.docker.com/examples/running_ssh_service/

1.
创建一个空目录用于存放Dockerfile

mkdir -p
/home/thm/docker/test/new_image

vim Dockerfile

Dockerfile的内容为:

  FROM tanghuimin0713/ubuntu_amd64:14.04
RUN apt-get update
RUN apt-get install -y openssh-server
#RUN mkdir /var/run/sshd
RUN sed -i 's/^PermitRootLogin/#PermitRootLogin/' /etc/ssh/sshd_config
RUN echo "PermitRootLogin yes" >> /etc/ssh/sshd_config
RUN echo "root:root" | chpasswd
EXPOSE

2. build a image

docker build -t tanghuimin0713/ubuntu_amd64_ssh .

3. run a container

docker run -d -p 2222:22 tanghuimin0713/ubuntu_amd64_ssh /usr/sbin/sshd -D

4. 主机下ssh登陆docker容器

ssh root@localhost -p 2222

密码为:root

root@ubuntu:/home/thm/docker/test/new_image# ssh root@localhost -p
The authenticity of host '[localhost]:2222 ([127.0.0.1]:2222)' can't be established.
ECDSA key fingerprint is bd::3f:e4:e3:bd:b4:::fe:1b::eb::f3:.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:2222' (ECDSA) to the list of known hosts.
root@localhost's password:
Welcome to Ubuntu 14.04 LTS (GNU/Linux 3.13.--generic x86_64) * Documentation: https://help.ubuntu.com/ 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@db36812760ac:~#

成功。

若在ssh登陆时提示:

@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
bd::3f:e4:e3:bd:b4:::fe:1b::eb::f3:.
Please contact your system administrator.
Add correct host key in /root/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /root/.ssh/known_hosts:
remove with: ssh-keygen -f "/root/.ssh/known_hosts" -R 172.17.0.2
ECDSA host key for 172.17.0.2 has changed and you have requested strict checking.
Host key verification failed.

rm $HOME/.ssh/known_hosts即可。

创建带sshd服务的docker image的更多相关文章

  1. 构建一个拥有sshd服务的docker镜像

    不直接描述结果,通过一个过程探究如何写一个 Dockerfile 一.环境 虚拟机CentOS7.4,Docker1.13.1 二.尝试步骤 1.下载基础镜像 docker pull alpine:3 ...

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

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

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

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

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

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

  5. 基于CentOS的SSHD服务的Docker镜像

    原文地址 1.Dockerfile文件 FROM registry.aliyuncs.com/acs-sample/centos:6 MAINTAINER xuqh "xqh_163@163 ...

  6. 利用Dockerfile文件创建带有sshd服务的centos镜像

    利用Dockerfile文件创建带有sshd服务的centos镜像 标签:dockerfile 1.安装docker并启动docker,不在赘述 2.创建使用Dockerfile安装sshd服务的目录 ...

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

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

  8. 「六」创建一个带 weblogic 服务的基础镜像

    Weblogic Weblogic 简单介绍以及其在 Docker 环境下的特殊应用 WebLogic是美国Oracle公司出品的一个application server确切的说是一个基于JAVAEE ...

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

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

随机推荐

  1. SOA 与 DDD

    SOA是技术架构方面,Evans DDD则是哲学方法论方面,所属方向不一样,或者说两者非常的无关.甚至是两个不同方向.使用DDD可以将系统从无到有到大建立起来,而大到一定程度,就需要SOA,整合异构. ...

  2. FBI传授9秘诀:如何看穿对方在撒谎 z

    第1招:不提及自身和姓名 美国赫特福德郡大学的心理学家韦斯曼说,〝人们在说谎时会本能地把自己从他们所说的谎言中剔除出去〞.所以如果你向某人提问时,他们总是反覆地省略〝我〞,他们就有被怀疑的理由了.反过 ...

  3. spring循环引用的问题

    很久没写技术贴了,这两天被spring的循环引用搞死了,发文记之. 前几天,项目结构做了调整,把我所在的项目代码嵌入另一个项目,然后就杯具了,症状如下: Bean with name ‘xxxServ ...

  4. 编写webpy程序,iep 报错,ulipad 运行正确

    在web.py编程中,使用模板文件时,iep下会报错.ulipad不会报错. 用python 运行不报错. 在寻找答案.初步估计是iep的python运行环境有问题. 如图:

  5. [ActionScript 3.0] AS3 时间日期格式化DateTimeFormatter类的运用

    import flash.globalization.DateTimeFormatter; var _timeFormatter:DateTimeFormatter; var _dateFormatt ...

  6. eclipse高效快捷键

    代码快速对齐:Ctrl+shift+f 添加注释,取消注释:Ctrl+shift+/    Ctrl+shift+\   Ctrl+/ Alt+Shift+R:一秒钟重命名 Ctrl+D:一秒钟删除行 ...

  7. 动画的特效Interpolator

    AccelerateDecelerateInterpolator 在动画开始与结束的地方速率改变比较慢,在中间的时候加速 AccelerateInterpolator  在动画开始的地方速率改变比较慢 ...

  8. Oracle 10046 event详解-转载

    0046事件概述Oracle的10046事件,可以跟踪应用程序所执行的SQL语句,并且得到其解析次数.执行次数,CPU使用时间等信息.这对我们分析.定位数据库性能问题是非常有用的. 10046 eve ...

  9. php mysql_select_db实例

    在php中,我们经常需要连接数据库和操作数据库, 在操作数据库之前,我们需要选择一个数据库,本文章通过实例向小伙伴们介绍php mysql_select_db选择数据库的使用方法. 首先介绍一下mys ...

  10. 动手学servlet(一) 第一个servlet程序

    1.文件>新建>动态WEB项目 "javaeedemo">在Java Resource的src下新建包“servletdemo”,包下新建一个类“MyServet ...