一、制作docker镜像的步骤

1、启动容器安装软件服务

2、将安装好服务的容器commit提交为镜像

3:、启动新容器来测试新提交的镜像

二、制作支持ssh远程登录的docker镜像

1、启动容器安装软件服务

1、启动容器

  1. [root@luoahong ~]# docker run -it -p 1022:22 --name luoahong4 centos:6.9

2、安装软件openssh-server

  1. [root@0485b9ecd1ad /]# yum install openssh-server -y
  2.  
  3. [root@0485b9ecd1ad /]# /etc/init.d/sshd start
  4. Generating SSH2 RSA host key: [ OK ]
  5. Generating SSH1 RSA host key: [ OK ]
  6. Generating SSH2 DSA host key: [ OK ]
  7. Starting sshd: [ OK ]
  8. [root@0485b9ecd1ad /]# netstat -lntup
  9. Active Internet connections (only servers)
  10. Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
  11. tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 118/sshd
  12. tcp 0 0 :::22 :::* LISTEN 118/sshd

3、测试是否可以上网

  1. [root@0485b9ecd1ad /]# curl www.baidu.com
  2. <!DOCTYPE html>
  3. <!--STATUS OK--><html> <head><meta http-equiv=content-type content=text/html;charset=utf-8><meta http-equiv=X-UA-Compatible content=IE=Edge><meta content=always name=referrer><link rel=stylesheet type=text/css href=http://s1.bdstatic.com/r/www/cache/bdorz/baidu.min.css><title>鐧惧害涓€涓嬶紝浣犲氨鐭ラ亾</title></head> <body link=#0000cc> <div id=wrapper> <div id=head> <div class="head_wrapper"> <div class="s_form"> <div class="s_form_wrapper"> <div id=lg> <img hidefocus=true src=//www.baidu.com/img/bd_logo1.png width=270 height=129> </div> <form id=form name=f action=//www.baidu.com/s class="fm"> <input type=hidden name=bdorz_come value=1> <input type=hidden name=ie value=utf-8> <input type=hidden name=f value=8> <input type=hidden name=rsv_bp value=1> <input type=hidden name=rsv_idx value=1> <input type=hidden name=tn value=baidu><span class="bg s_ipt_wr"><input id=kw name=wd class="s_ipt" value maxlength=255 autocomplete=off autofocus></span><span class="bg s_btn_wr"><input type=submit id=su value=鐧惧害涓€涓?class="bg s_btn"></span> </form> </div> </div> <div id=u1> <a href=http://news.baidu.com name=tj_trnews class="mnav">鏂伴椈</a> <a href=http://www.hao123.com name=tj_trhao123 class="mnav">hao123</a> <a href=http://map.baidu.com name=tj_trmap class="mnav">鍦板浘</a> <a href=http://v.baidu.com name=tj_trvideo class="mnav">瑙嗛</a> <a href=http://tieba.baidu.com name=tj_trtieba class="mnav">璐村惂</a> <noscript> <a href=http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u=http%3A%2F%2Fwww.baidu.com%2f%3fbdorz_come%3d1 name=tj_login class="lb">鐧诲綍</a> </noscript> <script>document.write('<a href="http://www.baidu.com/bdorz/login.gif?login&tpl=mn&u='+ encodeURIComponent(window.location.href+ (window.location.search === "" ? "?" : "&")+ "bdorz_come=1")+ '" name="tj_login" class="lb">鐧诲綍</a>');</script> <a href=//www.baidu.com/more/ name=tj_briicon class="bri" style="display: block;">鏇村浜у搧</a> </div> </div> </div> <div id=ftCon> <div id=ftConw> <p id=lh> <a href=http://home.baidu.com>鍏充簬鐧惧害</a> <a href=http://ir.baidu.com>About Baidu</a> </p> <p id=cp>©2017 Baidu <a href=http://www.baidu.com/duty/>浣跨敤鐧惧害鍓嶅繀璇?/a>  <a href=http://jianyi.baidu.com/ class="cp-feedback">鎰忚鍙嶉</a> 浜琁CP璇?30173鍙?nbsp; <img src=//www.baidu.com/img/gs.gif> </p> </div> </div> </div> </body> </html>

4、设置远程登录密码

  1. echo 123456|passwd --stdin root

5、远程测试

  1. [root@luoahong ~]# ssh root@192.168.228.134 -p 1022
  2. The authenticity of host '[192.168.228.134]:1022 ([192.168.228.134]:1022)' can't be established.
  3. RSA key fingerprint is SHA256:GBs8S1bKbhC5CxVHm+CeJouV5OJtpjes6mr9Dej7UZY.
  4. RSA key fingerprint is MD5:32:14:d6:77:c9:60:3b:66:8d:e3:a7:d1:88:d3:0f:fc.
  5. Are you sure you want to continue connecting (yes/no)? yes
  6. Warning: Permanently added '[192.168.228.134]:1022' (RSA) to the list of known hosts.
  7. root@192.168.228.134's password:
  8. [root@0485b9ecd1ad ~]#

2、将安装好服务的容器commit提交为镜像

1、提交镜像

  1. [root@luoahong ~]# docker commit luoahong4 centos6-ssh:v1
  2. sha256:e414afbffe052453b38faed463070f4a35663ca1c9f8d64e44e131369ba31630
  3. [root@luoahong ~]# docker ps -a
  4. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  5. 0485b9ecd1ad centos:6.9 "/bin/bash" 42 minutes ago Exited (0) 3 minutes ago luoahong4

3:、启动新容器来测试新提交的镜像

  1. [root@luoahong ~]# docker run -d -p 2022:22 centos6-ssh:v1 /usr/sbin/sshd -D
  2. 156d80283acf6f884df3589aeca834c38f2d78497e46e6580ce7cdf2b8f0e787
  3. [root@luoahong ~]# docker ps -a
  4. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  5. 156d80283acf centos6-ssh:v1 "/usr/sbin/sshd -D" 4 seconds ago Up 3 seconds 0.0.0.0:2022->22/tcp romantic_chandrasekhar
  6. 0485b9ecd1ad centos:6.9 "/bin/bash" 42 minutes ago Exited (0) 3 minutes ago luoahong4
  7. [root@luoahong ~]#

注意事项:记得一定要在启动容器的后面加上

  1. /usr/sbin/sshd -D

要不然会出现启动四秒退出3秒

  1. [root@luoahong ~]# docker ps -a
  2. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  3. 0485b9ecd1ad centos:6.9 "/bin/bash" 42 minutes ago Exited (0) 3 minutes ago luoahong4

再次测试

  1. [root@luoahong ~]# ssh root@192.168.228.134 -p 2022
  2. The authenticity of host '[192.168.228.134]:2022 ([192.168.228.134]:2022)' can't be established.
  3. RSA key fingerprint is SHA256:GBs8S1bKbhC5CxVHm+CeJouV5OJtpjes6mr9Dej7UZY.
  4. RSA key fingerprint is MD5:32:14:d6:77:c9:60:3b:66:8d:e3:a7:d1:88:d3:0f:fc.
  5. Are you sure you want to continue connecting (yes/no)? yes
  6. Warning: Permanently added '[192.168.228.134]:2022' (RSA) to the list of known hosts.
  7. root@192.168.228.134's password:
  8. Last login: Tue Jan 15 09:16:31 2019 from 192.168.228.134
  9. [root@156d80283acf ~]#

三、制作支持ssh+httpd双服务的镜像

1、启动容器安装软件服务

1、启动容器

  1. [root@luoahong ~]# docker run -it --name luoahong centos:6.9

2、安装软件服务

  1. [root@0d09d3a1591a /]# yum install httpd -y
  2. [root@0d09d3a1591a /]# yum install openssh-server -y

3、启动服务设置远程登录密码

  1. [root@0d09d3a1591a /]# /etc/init.d/sshd start
  2. Generating SSH2 RSA host key: [ OK ]
  3. Generating SSH1 RSA host key: [ OK ]
  4. Generating SSH2 DSA host key: [ OK ]
  5. Starting sshd: [ OK ]
  6. [root@0d09d3a1591a /]# echo 123456|passwd --stdin root
  7. Changing password for user root.
  8. passwd: all authentication tokens updated successfully.

4、编写容器启动脚本

  1. vi /init.sh
  2. #!/bin/bash
  3. /etc/init.d/httpd start
  4. /usr/sbin/sshd -D

2、将安装好服务的容器commit提交为镜像

  1. docker commit luoahong centos6-ssh-httpd:v1

3、启动新容器来测试新提交的镜像

1、命令行操作

  1. [root@luoahong ~]# docker run -d -p 8080:80 -p 1122:22 centos6-ssh-httpd:v1 /bin/bash /init.sh
  2. ea82b95830817f3087b35a6447dd9e62ea697dd6bb0306d0336d946392e03670
  3. [root@luoahong ~]# docker ps -a
  4. CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
  5. ea82b9583081 centos6-ssh-httpd:v1 "/bin/bash /init.sh" 9 seconds ago Up 9 seconds 0.0.0.0:1122->22/tcp, 0.0.0.0:8080->80/tcp stupefied_rosalind
  6. 0d09d3a1591a centos:6.9 "/bin/bash" 17 minutes ago Exited (0) 12 seconds ago luoahong
  7. 156d80283acf centos6-ssh:v1 "/usr/sbin/sshd -D" 19 minutes ago Up 19 minutes 0.0.0.0:2022->22/tcp romantic_chandrasekhar
  8. 0485b9ecd1ad centos:6.9 "/bin/bash" About an hour ago Exited (0) 23 minutes ago

2、浏览器测试截图 

3、注意事项

多服务的话需要编写容器脚本,启动命令格式如下

  1. [root@luoahong ~]# docker run -d -p 8080:80 -p 1122:22 centos6-ssh-httpd:v1 /bin/bash /init.sh

  

Docker:手动制作镜像 [五]的更多相关文章

  1. Docker如何制作镜像-Dockerfile的使用

    1:什么是Dockerfile Dockerfile是一个文本文档,可以通过docker build 命令构建成一个镜像. 我们可以在Dockerfile中定义一系列的命令,构建出我们想要的镜像. 想 ...

  2. Docker - 手动迁移镜像

    在没有Docker Registry时,可以通过docker save和docker load命令完成镜像迁移的过程,先将镜像保存为压缩包,然后在其他位置再加载压缩包. 将镜像保存为压缩包文件 [ro ...

  3. docker commit 制作镜像

    docker commit -m="commit jdk" --author="gutianlangyu" ae56f6cad215 gutianlangyu/ ...

  4. Docker——手动创建镜像

    启动一个进入容器: 在阿里云镜像下载一个nginx: 退出容器: 查看 : docker ps -a oldboyedu是用户名 就像githua一样也有用户名 v1是别名 在创建个容器使用刚才创建的 ...

  5. 利用docker进行基础镜像制作

    前言 最近想通过Javaee来开发博客,但是不想因为环境配置问题总是耗时间配置相关配置,所以萌生出用docker镜像来搭建web的系统环境,也是作为docker学习实践的笔记. docker hub注 ...

  6. centos7下安装docker(6镜像总结)

    学了很长时间的镜像了,从镜像的分层,缓存的特性,到制作镜像:通过docker commint和docker build创建,再到制作dockerfile以及dockerfile中常用的参数FROM,M ...

  7. 手动制作Docker镜像

    手动制作 Docker 镜像 前言 a. 本文主要为 Docker的视频教程 笔记. b. 环境为 CentOS 7.0 云服务器(用来用去感觉 Windows 的 Docker 出各种问题,比如使用 ...

  8. WIN7安装Docker Toolbox、制作镜像并发到阿里云

    一.安装Docker Toolbox,并配置国内源加速 WIndows7不支持Hyper-v,所以只能采用Docker Toolbox的方式使用Docker.传送门:http://mirrors.al ...

  9. Docker系列-(2) 镜像制作与发布

    上篇文章引入了Docker的基本原理和操作,本节文章主要介绍如何制作Docker镜像和发布. 镜像文件结构 Docker镜像的本质是一系列文件的集合,这些文件依次叠加,形成了最后的镜像文件,类似于下图 ...

随机推荐

  1. Operating system error 32(failed to retrieve text for this error. Reason: 15105)

    一台数据库服务器的事务日志备份作业偶尔会出现几次备份失败的情况,具体的错误信息为: DATE/TIME:    2018/7/30 12:10:52 DESCRIPTION: BackupDiskFi ...

  2. 安装Gradle(Windows & Linux)

    Gradle 是以 Groovy 语言为基础,面向Java应用为主.基于DSL(领域特定语言)语法的自动化构建工具.在github上,gradle项目很多,有的是gradel跟maven构建一块儿使用 ...

  3. 需求规格说明书(SRS)特点

    需求说明书的7大特征: 完整性 正确性 可行性 必要性 划分优先级 无二义性 可验证性 每条需求规格说明书的4大特点: 完整性 一致性 可修改性 可跟踪性 需求管理就是一种获取.组织并记录系统需求的系 ...

  4. 【vue】移动端demo资料

    http://imzjh.com/inew/#/(移动端demo) https://github.com/liangxiaojuan/eleme(饿了么git地址) https://github.co ...

  5. Selenium自动化测试之学会元素定位

    这是我经常被问到的一个问题,也是我很讨厌回答的问题,因为要想回答这个问题需要知道上下文.什么样式的元素,有哪些属性,是否有表单嵌套,都尝试了哪些定位方法...而且没几个提问者能事先详细的说明这些.哪儿 ...

  6. 在Mac OS X中完善PHP环境:memcache、mcrypt、igbinary

    本文环境: Mac OS X 10.8.5 Xcode 5.0 Mac OS X升级到10.8.5之后,内置的Apache升级到2.2.24,PHP升级到了5.3.26.本文以此环境为基础. 本文简介 ...

  7. 四:OVS+GRE之网络节点

    关于Neutron上的三种Agent的作用: Neutron-OVS-Agent:从OVS-Plugin上接收tunnel和tunnel flow的配置,驱动OVS来建立GRE Tunnel Neut ...

  8. Mysql_连接字符串

    1.本地数据库连接 <connectionStrings> <add name="ConnectionString" connectionString=" ...

  9. Entity Framework Core系列之DbContext(删除)

    上一篇我们介绍了Entity Framework Core系列之DbContext(修改),这一篇我们介绍下删除数据 修改实体的方法取决于context是否正在跟踪需要删除的实体. 下面的示例中con ...

  10. Mac之lnmp环境搭建

    之前在Windows上开发大部分都是使用的集成环境(xampp,phpstudy,wamp),可以完成日常便捷开发,有些时候却Windows下无法实现的就需要自己搭建虚拟机,在虚拟机中搭建lnmp环境 ...