docker 自诞生以来就是业内讨论得很火的一个话题,讨论程度仅此于openstack,后期应该会持续更新一些关于docker的内容:
docker是什么:简单来说docker 是软件工业的集装箱技术,可以实现相互隔离快速打包部署功能。
docker的安装和基本命令:
环境:
centos 7
docker安装:
[root@xiaoluo src]# yum install docker-io -y
##docker三个基本概念我之见:
1、镜像:可以理解成一个简单的系统,在上面可以部署和运行东西,用镜像可以启动一个容器。
2、容器:一个容器代表一个独立的任务,各容器之前相互隔离运行。
3、厂库:存放镜像的地方。
查看镜像:
[root@xiaoluo src]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE centos latest 60e65a8e4030 8 weeks ago 196.6 MB ubuntu 14.04 d55e68e6cc9c 11 weeks ago 187.9 MB
*TAG:镜像的标识,当使用push不加别的版本,默认使用的是latest.
IMAGE ID:镜像的唯一标识
查看可以下载镜像:
[root@xiaoluo src]# docker search centos
下载镜像可以docker pull xxx 从库里下载:
交互模式下启动docker:
[root@xiaoluo src]# docker exec -it centos /bin/bash [root@73aaba6e0cd1 /]#
启动docker:
[root@localhost ~]# docker run -d -p 2222:22 --name base csphere/centos:7.193e712c9d91467c0748961685e5453a7cd50898212191a762a36c6e933dbd539 *-d 后台启动 -p 本机端口2222映射到docker内部的22口(当然前提镜像是提前构建好,后期会讲到) --name 给容器起一个别名 base 镜像名称csphere/centos:7.1
查看正在启动的容器:
[root@localhost ~]# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES 93e712c9d914 csphere/centos:7.1 "/usr/bin/supervisord" About a minute ago Up About a minute 0.0.0.0:2222->22/tcp base
*查看所有的容器使用docker ps -a
删除容器:docker rm 93e712c9d914 (删除正在运行的容器docker rm f)
docker私有厂库:
当我们使用docker pull的时候默认是从官方的镜像去下载的,在我们环境中要是搭建一个本地的厂库存放我们的镜像就在合适不过了:
步骤:
1、下载一个registry容器,官方的images有时候被墙,我这里用的是灵雀云的镜像:
[root@localhost ~]# docker pull index.alauda.cn/library/registry
2、重命名一个镜像:测试用
[root@localhost ~]# docker tag 7e4f044162b7 192.168.63.198:5000/test
*把镜像ID为7e4f044162b7定义别名192.168.63.198:5000/test
[root@localhost native]# docker images REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE 192.168.63.198:5000/test latest 7e4f044162b7 8 days ago 724.9 MB csphere/mysql 5.5 7e4f044162b7 8 days ago 724.9 MB csphere/php-fpm 5.4 f149fdc3bb11 8 days ago 684.8 MB csphere/centos 7.1 e3570ed66dc9 8 days ago 591.3 MB index.alauda.cn/library/registry latest 07d93e41c370 4 weeks ago 422.8 MB docker.io/centos centos7.1.1503 fab4b1df8eb1 4 months ago 212.1 MB
3、本地启动本地镜像厂库:
[root@localhost ~]#docker run -d -p 5000:5000 -v /opt/data/registry/:/tmp/registry-dev 07d93e41c370
4、修改配置文件/etc/sysconf/docker:
打开/etc/sysconfig/docker,找到OPTIONS这一行,取消注释并修改如下: OPTIONS='--selinux-enabled --insecure-registry=yourip:5000'
**不然会报如下类似错:
unable to ping registry endpoint https://yourip:5000/v0/ v2 ping attempt failed with error: Get https://yourip:5000/v2/:EOF v1 ping attempt failed with error: Get https://yourop:5000/v1/_ping:EOF
5、提交镜像到本地库:
[root@localhost native]# docker push 192.168.63.198:5000/test The push refers to a repository [192.168.63.198:5000/test] (len: 1) Sending image list Pushing repository 192.168.63.198:5000/test (1 tags) f1b10cd84249: Image successfully pushed 172633e38420: Image successfully pushed fab4b1df8eb1: Image successfully pushed 7911a8421c83: Image successfully pushed af42609f6313: Image successfully pushed fa48118fc839: Image successfully pushed b7ca1c16fd68: Image successfully pushed fca316033a3c: Image successfully pushed 09f10030ab42: Image successfully pushed dc888ecebd54: Image successfully pushed 519dde82a4cc: Image successfully pushed 832a31216b14: Image successfully pushed e3570ed66dc9: Image successfully pushed e65974137a30: Image successfully pushed 2752603711a9: Image successfully pushed f027aaa7d0db: Image successfully pushed 6b59cfa21ac8: Image successfully pushed 94d6cbee9151: Image successfully pushed 5caacec189e1: Image successfully pushed 255629e3621b: Image successfully pushed 3ba1834f6adf: Image successfully pushed 7e4f044162b7: Image successfully pushed Pushing tag for rev [7e4f044162b7] on { http://192.168.63.198:5000/v1/repositories/test/tags/latest}
6、上传成功检查:
[root@localhost registry]# curl -X GET http://192.168.63.198:5000/v1/search {"num_results": 1, "query": "", "results": [{"description": "", "name": "library/test"}]}
到此本地厂库创建完成。