6

centos6升级docker1.6

 2 years ago
source link: https://www.hi-roy.com/posts/centos6%E5%8D%87%E7%BA%A7docker1-6/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

centos6升级docker1.6

2015-06-18

最近饱受Python版本、Django版本、系统不同导致部署方法不同这一类问题的折磨,虽然之前也有接触过docker但一直没抽出时间仔细学习,正好趁这个机会学习docker使用方法。

首先,想安装docker需要epel源,这里使用阿里源:

wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo
yum install docker-io

此时安装完的docker是1.5版本,而最新版本为1.6在epel源中并不存在,需要手动升级。

[root@localhost ~]# service docker start
Starting cgconfig service:                                 [  OK  ]
Starting docker:	                                   [  OK  ]
[root@localhost ~]# sudo docker -v
Docker version 1.5.0, build a8a31ef/1.5.0
[root@localhost ~]# wget https://get.docker.com/builds/Linux/x86_64/docker-latest -O /usr/bin/docker
--2015-06-18 12:02:19--  https://get.docker.com/builds/Linux/x86_64/docker-latest
Resolving get.docker.com... 162.242.195.82
Connecting to get.docker.com|162.242.195.82|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 15443675 (15M) [binary/octet-stream]
Saving to: “/usr/bin/docker”
100%[======================================================================================>] 15,443,675  72.4K/s   in 1m 55s  
2015-06-18 12:04:16 (132 KB/s) - “/usr/bin/docker” saved [15443675/15443675]
[root@localhost ~]# service docker restart
Starting docker:	                                   [  OK  ]
[root@localhost ~]# sudo docker -v
Docker version 1.6.2, build 7c8fca2

然后设为开机启动:chkconfig docker on

如果发现升级后docker无法启动,重启机器即可。

至于docker的基本概念和基本操作这里不多说了,可以参考这里。有很多小伙伴不知道怎么在容器中同时运行2个服务,这里给出我的Dockerfile,基于centos7版本支持ssh以及httpd服务:

FROM centos:latest
MAINTAINER shenyushun
RUN yum install wget -y
RUN wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
RUN yum makecache
RUN yum update -y
RUN yum install httpd -y
RUN yum install -y openssh openssh-server openssh-client
RUN sed -i "s/#UsePrivilegeSeparation.*/UsePrivilegeSeparation no/g" /etc/ssh/sshd_config && sed -i "s/UsePAM.*/UsePAM no/g" /etc/ssh/sshd_config
RUN echo 'root:asdasd' |chpasswd
RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
RUN yum install -y python-devel python-setuptools python-setuptools-devel
RUN easy_install pip
RUN pip install supervisor
RUN mkdir -p /var/log/supervisor
COPY supervisord.conf /etc/supervisord.conf
EXPOSE 22 80
CMD ["/usr/bin/supervisord"]

supervisord.conf文件内容如下:

[supervisord]
nodaemon=true
[program:sshd]
command=/usr/sbin/sshd -D
[program:httpd]
command=/usr/sbin/httpd -D FOREGROUND

把这2个文件放在同一个目录中,然后执行sudo docker build -t name/supervisord:centos

这样就会生成一个新的镜像,然后执行sudo docker run -p 2222:22 -p 8000:80 -t -i name/supervisord:centos启动容器即可。

至于使用ubuntu的小伙伴可以参考官网文档,或者使用我写的dockfile:https://github.com/shenyushun/docker-ubuntu14.04

最后再补充2个我最常用的指令,在初学时候经常要创建很多容器和镜像,但一个一个删太麻烦了:

docker rm $(docker ps -a -q)  #删除所有容器
docker rmi $(docker images | grep none | awk '{print $3}' | sort -r) #删除所有镜像

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK