Docker实践(1)—入门
tutorial
centos6.5环境。
# yum install docker-io -y
会依赖安装libcgroup,lxc,lxc-libs
启动docker
# service docker start
Starting cgconfig service: [确定]
Starting docker: [确定]
获取最新的docker image
# docker pull centos:latest
运行image
# docker run -i -t centos /bin/bash
bash-4.2# ls
bin dev etc home lib lib64 lost+found media mnt opt proc root run sbin selinux srv sys tmp usr var
bash-4.2# exit
提交更新
# docker commit -m="add net-tools" -a="dbyin" ad6327a8e166 dbyin/testrep
15a31c1fd4dd1a514b8d771e456fd9adfe206a70e4a672057363322c8b918a3a
删除镜像
# docker rmi dbyin/sshd
Untagged: dbyin/sshd:latest
Deleted: 3e6ddcc38145770486dbd2fcb5b3a6734fea447ab024c540e83d34acc8113a11
Deleted: ab8ed0aaabab96eaf1656539bb0f7990f1b114197d39308e93ab1160c222d4ff
Deleted: 4ffa765d3fafa308edba9de3e59582451d6658e4c50cf9d107bc18bfe415d2e9
Deleted: 95cc1fd701f6961585196a0b43e06404aa81f4ec65278d2249ad0716a2cf3d87
Deleted: ae21b4f05d98ea18aff9c4ed33343c933f6f11c8adb5342ab7e1ded6af8c5fd8
主要参考
[1]https://docs.docker.com/installation/centos/
通过docker部署ssh
# cat Dockerfile
FROM centos
MAINTAINER dbyin
RUN yum install -y openssh-server
RUN echo "root:root" | chpasswd
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
构建镜象
# docker build --rm -t dbyin/sshd .
Sending build context to Docker daemon 74.75 kB
Sending build context to Docker daemon
Step 0 : FROM centos
---> 1a7dc42f78ba
Step 1 : MAINTAINER dbyin
---> Running in f40dd8c16027
---> ae21b4f05d98
Removing intermediate container f40dd8c16027
Step 2 : RUN yum install -y openssh-server
---> Running in a298b82f5fc1
Loaded plugins: fastestmirror
Determining fastest mirrors
* base: mirrors.cug.edu.cn
* extras: mirrors.cug.edu.cn
* updates: mirrors.cug.edu.cn
Resolving Dependencies
--> Running transaction check
---> Package openssh-server.x86_64 0:6.4p1-8.el7 will be installed
--> Processing Dependency: openssh = 6.4p1-8.el7 for package: openssh-server-6.4p1-8.el7.x86_64
--> Running transaction check
---> Package openssh.x86_64 0:6.4p1-8.el7 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
openssh-server x86_64 6.4p1-8.el7 base 367 k
Installing for dependencies:
openssh x86_64 6.4p1-8.el7 base 341 k
Transaction Summary
================================================================================
Install 1 Package (+1 Dependent package)
Total download size: 708 k
Installed size: 1.8 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/base/packages/openssh-server-6.4p1-8.el7.x86_64.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for openssh-server-6.4p1-8.el7.x86_64.rpm is not installed
--------------------------------------------------------------------------------
Total 195 kB/s | 708 kB 00:03
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
Userid : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
Package : centos-release-7-0.1406.el7.centos.2.3.x86_64 (@CentOS/$releasever)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : openssh-6.4p1-8.el7.x86_64 1/2
Installing : openssh-server-6.4p1-8.el7.x86_64 2/2
Verifying : openssh-server-6.4p1-8.el7.x86_64 1/2
Verifying : openssh-6.4p1-8.el7.x86_64 2/2
Installed:
openssh-server.x86_64 0:6.4p1-8.el7
Dependency Installed:
openssh.x86_64 0:6.4p1-8.el7
Complete!
---> 95cc1fd701f6
Removing intermediate container a298b82f5fc1
Step 3 : RUN echo "root:root" | chpasswd
---> Running in 0aad665d3d2a
---> 4ffa765d3faf
Removing intermediate container 0aad665d3d2a
Step 4 : EXPOSE 22
---> Running in f3e0c11abc3f
---> ab8ed0aaabab
Removing intermediate container f3e0c11abc3f
Step 5 : CMD ["/usr/sbin/sshd", "-D"]
---> Running in 41d15fb205ff
---> 3e6ddcc38145
Removing intermediate container 41d15fb205ff
Successfully built 3e6ddcc38145
启动镜像
# docker run -d -P --name test_sshd dbyin/sshd
1348cf06d04b6b558e025e78d13b8f61d64e63301de06c8fc1da5c4d18c9b8f8
container的22被映射到host的49153端口。
停止container
# docker stop test_sshd
删除container
# docker rm test_sshd
错误1
Error: Cannot start container f82d9d3548b4d19cfb4599bb3b27f74b6d605f167456d509df722c749fdf476f: port has already been allocated
重启docker服务,参见https://github.com/dotcloud/docker/issues/6476
错误2
# ssh root@172.16.213.129 -p 49153 -v
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 172.16.213.129 [172.16.213.129] port 49153.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/identity-cert type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.4
debug1: match: OpenSSH_6.4 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug1: SSH2_MSG_KEXINIT sent
Read from socket failed: Connection reset by peer
增加以下内容重新构建镜像
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
然后出现
。。。
debug1: Exit status 254
增加以下内容重新构建镜像,参考这里
RUN sed -ri 's/UsePAM yes/#UsePAM yes/g' /etc/ssh/sshd_config
RUN sed -ri 's/#UsePAM no/UsePAM no/g' /etc/ssh/sshd_config
访问
# ssh root@172.16.213.129 -p 49153
主要参考
[1]Dockerizing an SSH Daemon Service
[2]Docker: Using Linux Containers to Support Portable Application Deployment
作者:YY哥
出处:http://www.cnblogs.com/hustcat/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。
Docker实践(1)—入门的更多相关文章
- 【转】Docker简介与入门
转自:https://segmentfault.com/a/1190000000448808 Docker是个新生的事物,概念类似虚拟化.网上关于Docker入门的东西已经很多了.不过本文探讨了Doc ...
- Docker实践,来自沪江、滴滴、蘑菇街架构师的交流分享
架构师小组交流会:每期选一个时下最热门的技术话题进行实践经验分享. 第一期主题:容器实践.Docker 作为当前最具颠覆性的开源技术之一,其轻量虚拟化.可移植性是CI/CD,DevOps,微服务的重要 ...
- docker 实践
https://doc.yonyoucloud.com/doc/docker_practice/etcd/etcdctl.html 启动http restful API docker批量映射端口 怎么 ...
- Spring实践系列-入门篇(一)
本文主要介绍了在本地搭建并运行一个Spring应用,演示了Spring依赖注入的特性 1 环境搭建 1.1 Maven依赖 目前只用到依赖注入的功能,故以下三个包已满足使用. <properti ...
- AspNetCore容器化(Docker)部署(一) —— 入门
一.docker注册安装 Windows Docker Desktop https://www.docker.com/products/docker-desktop Linux Docker CE h ...
- docker实践之docker-compose部署mysql
文章目录 docker实践之docker-compose部署mysql 1.安装部署docker 2.编写docker-compose文件 3.编写配置文件和初始化文件 4.启动数据库 5.检查初始化 ...
- Docker 学习 1 入门
Docker 学习 1 入门 dockert 安装. Mac Ubuntu 查看docker 版本 docker version 拉取image. docker pull e.g docker pul ...
- .Net Core in Docker极简入门(下篇)
Tips:本篇已加入系列文章阅读目录,可点击查看更多相关文章. 目录 前言 开始 Docker-Compose 代码修改 yml file up & down 镜像仓库 最后 前言 上一篇[. ...
- 【docker 一】入门实践、环境部署、基本操作指令、镜像库、数据卷
简述 `docker是如火如荼的容器技术,今后会陆续上传关于微服务技术的学习笔记,希望能和大家一起学习一起分享!` docker环境搭建 1.获取最新版的Docker安装包 $ wget -qO- h ...
随机推荐
- jquery实现checkbox的全选
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> < ...
- JS延时提示框
p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 31.0px Consolas; color: #2b7ec3 } p.p2 { margin: 0.0px ...
- PHP异步工作避免程序运行超时
应用案例: 某SNS社区要求用户给自己好友(好友数量上百个)发送邮件,每封邮件内容不一,发送后提示发送完毕! 常用PHP写法 sendmail.php <?php $count=count($e ...
- Java 第14章 字符串
字符串 基本数据类型和引用数据类型作为方法参数 ,在传递时有什么不同之处. 答:基本数据类型按值传递,相当于复制了一份过去. 引用数据类型是指向引用 内存地址,两个地方 根据地址使用同一份数据,如被更 ...
- WordPaster-Firefox浏览器控件安装方法
将WordPaster.xpi拖到Firefox扩展面板中安装 新版Firefox可能无法通过验证,如果Firefox提示无法安装,则需要进入about:config中将xpinstall ...
- WPF之 DataGrid数据绑定
DataGrid控件是显示数据的控件,从一个对象集合获取信息并在具有行和单元格的网格中显示信息.每行和一个单独的对象相对应,并且每列和该对象中的一个属性相对应. DataGrid控件添加了许多在WPF ...
- WebSphere试用过期问题处理
WebSphere Application Server的试用期为60天,过期将无法启动WAS. E:\IBM\WebSphere\AppServer\profiles\Dmgr01\bin>s ...
- RHEL5.8设置OpenSSH的X11 Forwarding功能
X11的Forwarding功能需要在SSH中进行设置,RedHat Enterprise Linux5.8默认使用的而是OpenSSH,现将设置方法记录如下: OpenSSH配置文件路径: /etc ...
- 蛙蛙推荐:如何实时监控MySql状态
大多网站的性能瓶颈都会出在数据库上,所以想把Mysql监控起来,就搜索了下相关资料. 后来和同事讨论了下cacti和nagios有些老套和过时,graphite比较时尚,然后就搜了下相关的资料,最后搞 ...
- iis php5.3.8 默认文档无效 404 - 找不到文件或目录
环境:WIN2008 R2 IIS7.5 / .NET4.X 新开1站点,使用php(5.3.8),默认首页文档已设置为index.php,网站所在目录的网站运行时用户权限正确,应用程序池是asp.n ...