Docker搭建开发测试环境_基础环境搭建

都是docker太火惹的”祸”,上面领导催的急,我也只能摸着石头过河了,实施部署不合理的地方勿喷,请拍砖。
1、安装docker,宿主机系统64位的centos6.6。

[root@xx-xxxx ~]# yum install http://mirrors.yun-idc.com/epel/6/x86_64/epel-release-6-8.noarch.rpm
[root@xx-xxxx ~]# yum install docker-io

2、自定义内网网桥,为以后不同宿主机的容器通信做好铺垫,自定义网桥前确保系统已经安装了bridge-utils工具包。

[root@xx-xxxx network-scripts]# cat ifcfg-br0
DEVICE=br0
BOOTPROTO=static
ONBOOT=yes
TYPE=Bridge
IPADDR=10.0.1.10
NETMASK=255.255.255.0
[root@xx-xxxx network-scripts]# cat ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
BRIDGE=br0
HWADDR=00:0C:29:08:63:C5
[root@xx-xxxx network-scripts]#

重启网络使网桥生效。
3、修改docker的启动参数,使docker监听默认的/var/run/docker.sock和本地的2345端口,方便以后调用docker的api。并指定docker的默认网桥为br0,重启docker生效。

[root@xx-xxxx ~]# cat /etc/sysconfig/docker
# /etc/sysconfig/docker
#
# Other arguments to pass to the docker daemon process
# These will be parsed by the sysv initscript and appended
# to the arguments list passed to docker -d

other_args="-H tcp://127.0.0.1:2345 -H unix:///var/run/docker.sock -b br0"
DOCKER_CERT_PATH=/etc/docker

# Location used for temporary files, such as those created by
# # docker load and build operations. Default is /var/lib/docker/tmp
# # Can be overriden by setting the following environment variable.
# # DOCKER_TMPDIR=/var/tmp
[root@xx-xxxx ~]#

4、获取官方的centos6.6镜像和私有仓库镜像。

[root@xx-xxxx ~]# docker pull centos:6.6
[root@xx-xxxx ~]# docker pull registry:latest

5、基于centos6.6镜像启动一个容器,安装nginx提供本地的yum源服务,方便本地编译制作镜像。

#nginx主机配置如下,其中的/opt/www/yumdata目录是挂载的宿主机/opt/data/yumdata/目录。
server {
   listen 80;
   autoindex on;
   autoindex_exact_size off;
   autoindex_localtime on;

   location / {
       root /opt/www/yumdata;
       autoindex on;
   }
}

6、基于registry启动一个容器,作为本地的私有仓库,监听本地的5000端口,并将宿主机的/opt/data/registry挂载到容器的/tmp/registry目录。

[root@xx-xxxx ~]# docker run -d -p 5000:5000 -v /opt/data/registry:/tmp/registry --name=registry registry

将官方pull下来的centos6.6镜像push到本地仓库,方便本地编译制作镜像。

[root@xx-xxxx ~]# docker tag 35e9 127.0.0.1:5000/centos:6.6
[root@xx-xxxx ~]# docker pusll 127.0.0.1:5000/centos:6.6
[root@xx-xxxx ~]# curl http://127.0.0.1:5000/v1/search
{"num_results": 6, "query": "", "results": [{"description": "", "name": "library/centos"}]}

有了本地的私有仓库和本地yun源后就可以很方便的进行下一步,用Dockerfile配置文件docker build镜像了。
文章出处:http://www.xiaomastack.com/2015/04/05/docker-dev-test-base/

发表评论:

你的电子邮件地址将不会被公开.

− 7 = 3