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 ...
随机推荐
- verilog中的for循环问题
module mult_for(outcome,a,b);parameter SIZE=8;input[SIZE:1] a,b;output reg[2*SIZE:1] outcome;integer ...
- aceAdmin fuelux tree 从后台获取数据,并设置节点ID等属性
如题,从后台封装数据,有两种方式渲染节点的数据: 1.全部节点加载 2.根据父节点加载子节点 首先,先介绍下第一种渲染方式: 后台返回数据格式(所有的附加属性,都可放在additionalParame ...
- String reorder
本问题出自:微软2014实习生及秋令营技术类职位在线测试 (Microsoft Online Test for Core Technical Positions) Description For th ...
- java内部类和匿名内部类
内部类即是包含在类里面的又一个类. java内部类分为: 成员内部类.静态嵌套类.方法内部类.匿名内部类 . 内部类的共性 (1).内部类仍然是一个独立的类,在编译之后内部类会被编译成独立的.clas ...
- React和ES6(二)ES6的类和ES7的property initializer
React与ES6系列: React与ES6(一)开篇介绍 React和ES6(二)ES6的类和ES7的property initializer React与ES6(三)ES6类和方法绑定 React ...
- 给AOP的after函数使用原函数局部变量
引:AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术. 这里我们可以理解为在执行某函数时,要先执 ...
- 6.4 APK包限制
Google 2015年 9月28日公告:为了Android开发商可以制作出更加复杂的app和游戏,Google Play游戏包体(APK)大小由原来的50MB提高到100MB.但是针对Android ...
- h5图片上传预览与拖拽上传
图片上传: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...
- spinner与arrays.xml的使用
在Android中,用string-array是一种简单的提取XML资源文件数据的方法. 例: 把相应的数据放到values/arrays.xml文件里 <?xml version=" ...
- Caffe学习系列(20):用训练好的caffemodel来进行分类
caffe程序自带有一张小猫图片,存放路径为caffe根目录下的 examples/images/cat.jpg, 如果我们想用一个训练好的caffemodel来对这张图片进行分类,那该怎么办呢? 如 ...