一、制作docker镜像的步骤

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

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

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

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

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

1、启动容器

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

2、安装软件openssh-server

[root@0485b9ecd1ad /]# yum install openssh-server -y

[root@0485b9ecd1ad /]# /etc/init.d/sshd start
Generating SSH2 RSA host key: [ OK ]
Generating SSH1 RSA host key: [ OK ]
Generating SSH2 DSA host key: [ OK ]
Starting sshd: [ OK ]
[root@0485b9ecd1ad /]# netstat -lntup
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 118/sshd
tcp 0 0 :::22 :::* LISTEN 118/sshd

3、测试是否可以上网

[root@0485b9ecd1ad /]# curl www.baidu.com
<!DOCTYPE html>
<!--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、设置远程登录密码

echo 123456|passwd --stdin root

5、远程测试

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

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

1、提交镜像

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

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

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

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

/usr/sbin/sshd -D

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

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

再次测试

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

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

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

1、启动容器

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

2、安装软件服务

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

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

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

4、编写容器启动脚本

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

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

docker commit luoahong centos6-ssh-httpd:v1

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

1、命令行操作

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

2、浏览器测试截图 

3、注意事项

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

[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. python3字符串格式化format()函数的简单用法

    format()函数 """ 测试 format()函数 """ def testFormat(): # format()函数中有几个元素, ...

  2. Docker 启动,进入容器,查看log命令

    1.启动一个容器 docker run -d -P training/webapp python app.py -d:让容器在后台运行. -P:将容器内部使用的网络端口映射到我们使用的主机上. 如果需 ...

  3. isinstance_issubclass

    isinstance和issubclass分别是检验是不是对象是不是类的实例化,和子类是不是这个父类的子类 class A:pass class B(A):pass a = A() print(isi ...

  4. 爬虫系列二(数据清洗--->bs4解析数据)

    一 BeautifulSoup解析 1 环境安装 - 需要将pip源设置为国内源,阿里源.豆瓣源.网易源等 - windows (1)打开文件资源管理器(文件夹地址栏中) (2)地址栏上面输入 %ap ...

  5. webpack开发环境和生产环境切换原理

    在package.json中有如下设置: "scripts": {    "dev": "node build/dev-server.js" ...

  6. 好程序员技术教程分享JavaScript运动框架

    好程序员技术教程分享JavaScript运动框架,有需要的朋友可以参考下. JavaScript的运动,即让某元素的某些属性由一个值变到另一个值的过程.如让div的width属性由200px变到400 ...

  7. js获取浏览器窗体最大化事件

    <mce:script language="javascript"><!--function ReSet() {document.getElementById(& ...

  8. 嵌入式操作系统---打印函数(printf/sprintf)的实现

    一.打印函数简介 作用:将“给定的内容”按照“指定的格式”输出到“指定目标内”. 打印函数的基本格式: char print_buf[BUF_SIZE]; void printf(const char ...

  9. ibatisNet MERGE INTO ORA-00911: 无效字符

    在sql工具中测试正常,放到代码中出现 “ORA-00911: 无效字符” 错误时,请检查sql语句是否有分号.

  10. 拜托!面试请不要再问我Spring Cloud底层原理

    概述 毫无疑问,Spring Cloud是目前微服务架构领域的翘楚,无数的书籍博客都在讲解这个技术.不过大多数讲解还停留在对Spring Cloud功能使用的层面,其底层的很多原理,很多人可能并不知晓 ...