https://blog.tankywoo.com/docker/2014/05/08/docker-4-summary.html
https://yeasy.gitbooks.io/docker_practice/content/basic_concept/container.html
centos7.x系列的yum源中自带了docker的rpm包,安装比较简单
# yum install docker -y
安装过程中可能会遇到lvm2包依赖冲突,如不使用,卸载即可
# yum remove lvm2
启动服务
# service docker start
查看版本
# docker -v
Docker version 1.10.3, build d381c64-unsupported
获取BusyBox镜像
# docker pull busybox
创建容器并echo一句话
# docker run busybox /bin/echo Starting docker trip?
Starting docker trip?
centos6.x系列需要安装epel源,并且升级内核到3.10版本否则docker不能正常运行
基于git克隆安装https://github.com/llitfkitfk/docker-tutorial-cn
# git clone git://github.com/llitfkitfk/docker-tutorial-cn.git
# cd docker-tutorial-cn/
# ./docker_install.sh
##执行此步骤如果报下文错误需要修改/etc/yum.repos.d/epel.repo文件,取消baseurl的注释,注释掉mirrorlist
Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again
# ./docker_config.sh ##可根据实际情况修改docker image的储存路径,此处配置到/mnt/docker,默认路径是/var/lib/docker
# mkdir /mnt/docker
# ./start_docker.sh ##开启docker服务
docker: relocation error: docker: symbol dm_task_get_info_with_deferred_remove, version Base not defined in file libdevmapper.so.1.02 with link time reference
# yum upgrade device-mapper-libs ##启动报错,需要安装依赖
# docker info ##检查Docker是否正确安装
Containers: 0
Images: 0
Storage Driver: devicemapper
Pool Name: docker-253:0-1182180-pool
Pool Blocksize: 65.54 kB
Backing Filesystem: extfs
Data file: /dev/loop0
Metadata file: /dev/loop1
Data Space Used: 305.7 MB
Data Space Total: 107.4 GB
Data Space Available: 28.35 GB
Metadata Space Used: 733.2 kB
Metadata Space Total: 2.147 GB
Metadata Space Available: 2.147 GB
Udev Sync Supported: true
Deferred Removal Enabled: false
Data loop file: /var/lib/docker/devicemapper/devicemapper/data
Metadata loop file: /var/lib/docker/devicemapper/devicemapper/metadata
Library Version: 1.02.117-RHEL6 (2016-04-01)
Execution Driver: native-0.2
Logging Driver: json-file
Kernel Version: 2.6.32-358.6.2.el6.x86_64
Operating System: <unknown>
CPUs: 12
Total Memory: 3.662 GiB
Name: localhost
ID: SAJR:3GXN:LA3H:XV3F:4WUS:PJNS:N7YI:IXS2:LCO2:J6WL:AMCV:AEBW
在docker index中搜索centos相关的image
# docker search centos
从docker registry server拉取centos镜像
# docker pull centos
创建一个运行bash应用的容器,一直报错,使用-d命令查看进行运行信息,发现内核版本过低
# docker run -i -t centos /bin/bash
Error response from daemon: Cannot start container 317bcef4837ad90112a9021012f243bdf92e594h file or directory
# docker -d
WARN[0000] You are running linux kernel version 2.6.32-358.6.2.el6.x86_64, which might be pgrade your kernel to 3.10.0.
于是升级内核到3.10
http://my.oschina.net/denglz/blog/487332
安装kernel-lt(long-term)
# yum install http://www.elrepo.org/elrepo-release-6-5.el6.elrepo.noarch.rpm
# yum --enablerepo=elrepo-kernel install kernel-lt -y
新安装的内核已经自动写入了grub.conf文件,只需修改Grub引导顺序,重启即可
# sed -i 's/default=1/default=0/' /etc/grub.conf
内核已经更新
# uname -a
Linux localhost.localdomain 3.10.102-1.el6.elrepo.x86_64 #1 SMP Tue Jun 14 11:40:50 EDT 20
列出images
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos latest d83a55af4e75 2 weeks ago 196.7 MB
使用centos这个镜像创建container进入交互模式,login shell是/bin/bash
Docker制作centos6.5基础镜像
http://blog.chinaunix.net/uid-20788636-id-4909654.html
# yum install febootstrap
# mkdir /dockerimg/centos6.5 创建镜像文件保存目录
# febootstrap -i bash -i wget -i yum -i iputils -i iproute -i man -i vim -i openssh-server -i openssh-clients -i tar -i p7zip -i net-tools centos6.5 /dockerimg/centos6.5 http://vault.centos.org/6.5/os/x86_64/
-i指定安装的包 centos6.5标识OS版本
# cp /etc/skel/.bash* /dockerimg/centos6.5/root/
# cd /dockerimg/centos6.5
# tar -c .|docker import - centos6.5 导入镜像文件
63a8a89d802130fa35f0661402bf776069dcfd2cf83da553d4874c6a6c7ad056
# docker images 已经成功导入,使用docker run命令就可以基于centos6.5创建容器使用了
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos6.5 latest 63a8a89d8021 About a minute ago 372 MB