REPOSITORY TAG IMAGE ID CREATED SIZE
docker.io/centos 7 196e0ce0c9fb 5 weeks ago 197 MB
docker.io/centos 6 5dedbd63518e 6 weeks ago 194 MB
docker.io/centos 5 1ae98b2c895d 14 months ago 285 MB
启动各版本创建一个基础容器
CentOS5容器
sudo docker run -it --hostname centos5 --name centos5 docker.io/centos:5 /bin/bash
[huatai@devstack ~]$ sudo docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
local centos7 89d417f57e5e 12 seconds ago 459 MB
local centos6 6d071df1d7cb 48 seconds ago 428 MB
local centos5 d0fcf242634d 2 minutes ago 546 MB
docker.io/centos 7 196e0ce0c9fb 5 weeks ago 197 MB
docker.io/centos 6 5dedbd63518e 6 weeks ago 194 MB
docker.io/centos 5 1ae98b2c895d 14 months ago 285 MB
使用镜像创建容器
centos 5
sudo docker run -it --hostname dev5 --name dev5 local:centos5 /bin/bash
centos 6
sudo docker run -it --hostname dev6 --name dev6 local:centos6 /bin/bash
centos 7
sudo docker run -it --hostname dev7 --name dev7 local:centos7 /bin/bash
FROM ubuntu
... usual apt-get steps + adding github to known_hosts
RUN wget -O ~/.ssh/id_rsa http://192.168.99.1:8080/secrets/file/id_rsa && ssh -T git@github.com && rm ~/.ssh/id_rsa
通过Dockerfile创建镜像
上述手工完成的工作,可以改写成Dockerfile如下
Dockerfile
FROM docker.io/centos:5
MAINTAINER vincent huatai <vincent@huatai.me>
RUN yum clean all
RUN yum -y update
RUN yum -y install which mlocate net-tools rsyslog file ntp ntpdate \
wget tar bzip2 screen sysstat unzip nfs-utils parted lsof man bind-utils \
gcc gcc-c++ make telnet flex autoconf automake ncurses-devel crontabs \
zlib-devel git openssh-clients openssh-server initscripts
# Add ssh public key for login
RUN mkdir -p /root/.ssh
ADD authorzied_keys /root/.ssh/authorzied_keys
RUN chmod 600 /root/.ssh/authorzied_keys
RUN chmod 700 /root/.ssh
执行命令
docker build -t local:centos5 .
从构建的镜像启动容器
docker run -itd --hostname dev5 --name dev5 local:centos5 /bin/bash