Docker is an open-source application container engine that allows developers to package their applications and rely on the environment into a portable container and publish them to any popular Linux machine.
First, installation
1. Installation ready up kernel to 3.8
rpm--importhttps://www.elrepo.org/RPM-GPG-KEY-elrepo.org
or
Yum Install epel-release
RPM-UVHhttp://www.elrepo.org/elrepo-release-6-6.el6.elrepo.noarch.rpm
Yum--enablerepo=elrepo-kernel Install kernel-ml-y
http://elrepo.org/tiki/tiki-index.php:
sed-n '/default/c default=1 '/boot/grub/grub.conf #以新内核启动
reboot
2. Installing Docker
Yum install Docker-io device-mapper-event-libs-y
Service Docker start #启动服务
Chkconfig Docker on
Troubleshooting information:
docker-d
info[0000] +job serveapi (unix:///var/run/docker.sock)
info[0000] warning:you is running Linux kernel version 2.6.32-431.el6.x86_64, which might be unstable running Docke R. Upgrade your kernel to 3.8.0.
docker:relocation error:docker:symbol dm_task_get_info_with_deferred_remove, version Base not defined in file Libd evmapper.so.1.02 with link Time reference
second, common command options
Usage:docker [OPTIONS] COMMAND [arg ...]
Docker search Ubuntu #搜索镜像
Docker pull Ubuntu #获取镜像 (default = Lastest)
Docker pull centos:6.6 #获取指定镜像tag
Docker [-v]|version #版本信息
Docker Images #列出本地镜像
Docker PS #查看容器信息
Docker stats 18534AE7FBBC #容器运行状态
Docker stop 0185e1cb9466 #终止指定容器
Docker logs-f web-15 #查看指定容器log
Docker rm 18534ae7fbbc #删除容器
Docker rmi Ubuntu #删除镜像
Docker inspect 18534AE7FBBC |grep ' "Pid" ' #查看容器Pid
Docker inspect 18534AE7FBBC |grep ' "IPAddress": ' #查看容器IP
Docker inspect 18534AE7FBBC |grep ' "Gateway": ' #查看容器网关
Docker RM $ (Docker ps-a |grep-v ' up ' |cut-d ""-f1) #删除所有未启动的容器
Docker RM $ (Docker ps-a-Q) #删除所有容器
Iii. two ways to start a container
1, one is to create a new container based on the mirror and start
Docker run-it Ubuntu + command #执行完就退出
Docker run-it Ubuntu "PS"
Docker run-it Ubuntu/bin/bash #启动一个容器的bash,-t assign pseudo terminal,-I open input
Docker Run--help
Mans Docker-run
Docker run-dit--name Web01 ubuntu:14.04/bin/bash #-d background Run
2. A container that starts the terminating state with the start option
Docker start web-01
Iv. Connecting (entering) the container: (Attach, not recommended)
1, attach (with option, not recommended)
Docker Attach web-01
2, Nsenter (enter the namespace, recommended)
Yum install util-linux-y #安装nsenter所属软件包
Docker PS #查看已启动容器
Docker Inspect--format "{{. State.pid}} "container id| container name #获取容器PID
nsenter-t 9724-m-u-i-n-p-r-w #进入容器
hostname web01-3797 #给容器主机名加入PID, convenient for next entry
3. SSH
Docker run-t-i-c 100-m 256mb-h web-19-p 2220:22--restart= "Always"--name= "web-19" Centos:6.6/bin/bash #之后自动进入 Container Bash
yum-y Install openssh-server openssh-clients #安装SSH
chkconfig sshd on
Service sshd Start
ifconfig #查看容器IP
passwd Root #修改root密码
ssh [email protected] container ip-p2220
Docker commit web-16 centos/sshd #容器保存为镜像 to facilitate next call
v. Export Import:
1. Container
Docker export 18534AE7FBBC >/opt/docker/ubuntu.tar #导出容器
Cat/opt/docker/ubuntu.tar |docker import-test/ubuntu:v1.0 #导入容器
2. Mirror
Docker save-o Ubuntu_14.04.tar ubuntu:14.04 #导出镜像
Docker load--input ubuntu_14.04.tar #载入镜像
Six, port mapping
Docker Run--help
Docker run-tid-c 100-m 512mb-h web-14-p 192.168.18.10:80:80--name= "web-14" Centos:6.6/bin/bash #绑定指定IP端口
Docker run-tid-c 100-m 512mb-h web-15-p 80:80--name= "web-15" Centos:6.6/bin/bash #绑定全部IP端口
Docker run-tid-c 100-m 256mb-h web-16-p 2222:22--restart= "Always"--name= "web-16" Centos:6.6/bin/bash #自启动, bound s SH Port
Docker run-tid-c 100-m 512mb-h web-117-p 800:80--name= "web-117" Centos:6.6/bin/bash #绑定全部IP端口
Vii. Creating and mounting local data volumes
1. Create:
Docker run-dit--name web12-v/webapp centos:6.6/bin/bash
Docker run-dit--name web02-v/webapp centos:6.6/bin/bash
Docker run-dit--name web05-v/webapp centos:6.6/bin/bash
2. Mounting
Docker run-dit--name web11-v/opt/downloads:/mnt centos:6.6/bin/bash
Docker run-dit--name web11-v/opt/downloads:/mnt:ro centos:6.6/bin/bash
3. Data Volume container:
Docker run-d-v/dbdata--name dbdata training/postgres echo data-only container for Postgres #创建一个命名的数据卷容器 dbdata
Docker run-d--volumes-from dbdata--name db1 training/postgres #其他容器中使用--volumes-from to mount a data volume in a dbdata container
For more information:
Http://dockerpool.com/books
https://docs.docker.com/installation/#installation
Docker Toss notes