参考资源:
http://blog.iyunv.com/kongxx?viewmode=contents
http://my.oschina.net/feedao/blog
==============================
win8.1 + virtual box, 运行 centos6.4 64bit, 内网通过代理上网。
如下操作基本都在root下进行。
尝试自己建立Docker镜像
1,阿里云镜像
执行如下脚本,将资源镜像执行阿里云
#!/bin/bash
mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo
mv /etc/yum.repos.d/epel.repo /etc/yum.repos.d/epel.repo.backup
mv /etc/yum.repos.d/epel-testing.repo /etc/yum.repos.d/epel-testing.repo.backup
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum makecache
在windows下编辑后,回车换行符需要替换
使用dos2unix命令
$ dos2unix -k sample.txt
2,wget上网代理
root用户
增加/root/.wgetrc 文件,定义代理服务器及用户名密码
http-proxy=proxy_ip:port
https-proxy=proxy_ip:port
ftp-proxy=proxy_ip:port
proxy-user=username
proxy-passwd=password
重新登录一下
联网不使用代理时使用 --no-proxy 参数
1,安装docker
对于CentOS6,可以使用EPEL库安装Docker,命令如下
# yum install http://mirrors.yun-idc.com/epel/6/i386/epel-release-6-8.noarch.rpm
# yum install docker-io
安装之后启动Docker服务,并让它随系统启动自动启动。
# service docker start
# chkconfig docker on
2,安装工具debbootstrap
yum -y install debootstrap
3,编写自己的Dockerfile,以ubuntu 14.04 ssh为例: *在docker build 时使用
# 选择一个已有的os镜像作为基础
FROM ubuntu
# 镜像的作者
MAINTAINER Leonard Tian "leonard.tianlb@gmail.com"
# 安装openssh-server和sudo软件包,并且将sshd的UsePAM参数设置成no
RUN apt-get install -y openssh-server sudo
RUN sed -i 's/UsePAM yes/UsePAM no/g' /etc/ssh/sshd_config
# 添加测试用户tianlb,密码123456,并且将此用户添加到sudoers里
RUN useradd tianlb
RUN echo "tianlb:123456" | chpasswd
RUN echo "tianlb ALL=(ALL) ALL" >> /etc/sudoers
# 下面这两句比较特殊,在centos6上必须要有,否则创建出来的容器sshd不能登录
# RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
# RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
# 启动sshd服务并且暴露22端口
RUN mkdir /var/run/sshd
EXPOSE 22
CMD ["/usr/sbin/sshd", "-D"]
注意Dockerfile文件的首字母大写
将镜像源转换为阿里云的,参考1.阿里云镜像
4, 创建image
debootstrap --arch amd64 --include=vim,openssh-server,openssh-client trusty ubuntu-trusty http://mirrors.aliyun.com/ubuntu/
cd ubuntu-trusty
tar -c . | docker import - ubuntu1404-base
# docker build -t ubuntu1404-ssh .
* docker build 目前有问题
查看docker image
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
ubuntu1404-base latest 6457f5dac973 About an hour ago 287.5 MB
5, 创建容器
docker run -t -i ubuntu1404-base /bin/bash
直接进入容器,可以进行基本操作,如ls等。
6, 异常处理
Docker在CentoOS6运行一个容器的时候出现下面的错误
# docker run -i -t ubuntu1404-base /bin/bash
unable to remount sys readonly: unable to mount sys as readonly max retries reached
碰到这个问题需要修改Docker的配置参数把/etc/sysconfig/docker文件中的other-args更改为:
other_args="--exec-driver=lxc --selinux-enabled"
然后重新启动Docker服务
sudo /etc/init.d/docker restart
7, 其他命令
#查看docker容器,及状态
docker ps -a
#启动容器
docker start ID
#停止容器
docker stop ID
#删除容器
docker rm ID
--End--
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com