docker 搭建
dockerdocker 介绍
docker 镜像管理
docker 容器管理
docker 网络访问
docker 数据管理
docker 镜像构建
docker 私有仓库
docker 核心技术
docker 生产实践
docker 生态圈
Docker 组成(Docker clientDocker Server)
Docker 组件 (镜像、容器、仓库)
docker 部署
docker search \\搜索镜像
docker pull \\ 获取镜像
docker images \\ 查看镜像
docker rmi \\ 删除镜像
docker -d\\ -d 参数后台启动
ForRHEL/CentOS 5
rpm -ivh http://mirrors.ustc.edu.cn/fedor ... ease-5-4.noarch.rpm
For RHEL/CentOS 6
rpm -ivh http://dl.fedoraproject.org/pub/ ... ease-6-8.noarch.rpm
# yum -y install docker-io
# /etc/init.d/docker start
Starting docker:
注释报错
# docker -d
WARN You are running linux kernel version 2.6.32-504.16.2.el6.x86_64, which might be unstable running docker. Please upgrade your kernel to 3.10.0.
INFO Listening for HTTP on unix (/var/run/docker.sock)
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 install device-mapper
# docker search centos \\搜索 centos 镜像
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 2218
jdeathe/centos-ssh CentOS-6 6.7 x86_64 / CentOS-7 7.2.1511 x8... 22
jdeathe/centos-ssh-apache-php CentOS-6 6.7 x86_64 / Apache / PHP / PHP M... 17
million12/centos-supervisor Base CentOS-7 with supervisord launcher, h... 11
nimmis/java-centos This is docker images of CentOS 7 with dif... 10
torusware/speedus-centos Always updated official CentOS docker imag... 7
nickistre/centos-lamp LAMP on centos setup 3
nathonfowlie/centos-jre Latest CentOS image with the JRE pre-insta... 3
centos/mariadb55-centos7 3
consol/sakuli-centos-xfce Sakuli end-2-end testing and monitoring co... 2
blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1
lighthopper/orientdb-centos A Dockerfile for creating an OrientDB imag... 1
yajo/centos-epel CentOS with EPEL and fully updated 1
pacur/centos-7 Pacur CentOS 7 1
darksheer/centos Base Centos Image -- Updated hourly 1
timhughes/centos Centos with systemd installed and running 1
lighthopper/openjdk-centos A Dockerfile for creating an OpenJDK image... 0
januswel/centos yum update-ed CentOS image 0
repositoryjp/centos Docker Image for CentOS. 0
ustclug/centos USTC centos 0
grayzone/centos auto build for centos. 0
ericuni/centos centos dev 0
grossws/centos CentOS 6 and 7 base images with gosu and l... 0
jsmigel/centos-epel Docker base image of CentOS w/ EPEL installed 0
labengine/centos Centos image base 0
# docker pull centos\\获取镜像
# docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
centos latest eeb3a076a0be 5 weeks ago 196.7 MB
# docker run centos /bin/echo 'Hello world' \\创建容器
Hello world
# docker ps -a \\查看容器
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
25f51a2662ef centos "/bin/echo 'Hello wo About a minute ago Exited (0) About a minute ago lonely_hypatia
# docker run --name mydocker -it centos /bin/bash \\mydocker 容器起的名字 、并进入容器
#
# docker run -d --name mynginx nginx \\nginx 容器 并在后台启动
# docker inspect --format "{{.State.Pid}}" mynginx \\提取 mynginx pid
7309
# nsenter --target 7309 --mount --uts --ipc --net --pid \\nsenter 进入 后台启动mynginx容器中
脚本执行进入mynginx 容器中
root@CentOS-6 data]# vi nginx.sh
#!/bin/bash
CNAME=$1
CPID=$(docker inspect --format "{{.State.Pid}}" $CNAME)
nsenter --target "$CPID" --mount --uts --ipc --net --pid
# ./nginx.sh mynginx
docker 网络设置
映射端口
1、随机映射 2、指定映射
docker run -P \\随机映射 是大P
# docker run -d -P --name mynginx1 nginx\\创建了一个新的 nginx 并把端口随机映射出来
docker run -p \\指定映射端口 是小p
# docker run -d -p 91:80 --name mynginx2 nginx \\创建一个新的 nginx 并把端口指定映射出来91 是指定端口 80 是容器端口
docker run -p IP:主机端口号:容器端口号
docker run -p IP::容器端口
docker run -pIP:容器端口 \\使用多个 -p IP指定多个容器端口
docker 数据管理
# docker run -it --name volume-test1-h nginx -v /data nginx\\启动容器 -h指定主机名 -v 指定数据卷轴 启nginx容器创建一个data 容器卷
-it -i 是保持容器打开状态 -t 启动一个tty
# docker inspect -f {{.Volumes}} volume-test1\\查看 物理机挂再在容器上的目录
物理机上指定目录挂载在容器上面
# docker run -it --name volume-test2 -h nginx -v /opt:/opt centos \\源和目标中间用冒号 假如要是设置为只读的话 那么 -v /opt:/opt:ro centos \\还可以挂载文件
# ls /opt/
libedit-2.11-4.20080712cvs.1.el6.x86_64.rpmlrzsz-0.12.20-27.1.el6.x86_64.rpm
数据卷容器
# docker run -it --name volume-test4 --volumes-from volume-test1 centos\\挂载 其他停止容器的数据卷
把 volume-test1 做数据共享 挂载到 test4上
docker 镜像构建
root@CentOS-6 /]# docker run --name nginx-man -it centos\\进入centos容器里 必须可以连通网络
[*]
页:
[1]