使用host模式搭建dockyard环境

来源:互联网 发布:fm2016开档曼联数据 编辑:程序博客网 时间:2024/06/08 16:42

一、在宿主主机的相关配置

1)下载docker的bin文件,步骤如下:

wget https://get.docker.com/builds/Linux/x86_64/docker-1.8.3mv docker-1.8.3 dockercp docker /usr/bin

2)配置containerops网络

打开 /etc/hosts,添加

127.0.0.1       containerops.me

二、在容器内的相关配置

1)配置runtime文件

vim dockyard/conf/runtime.conf
添加如下内容:
runmode = devlistenmode = httpshttpscertfile = cert/containerops/containerops.crthttpskeyfile = cert/containerops/containerops.key[log]filepath = log/containerops-log[db]uri = localhost:6379registry = 0.9runmode = devlistenmode = httpshttpscertfile = cert/containerops/containerops.crthttpskeyfile = cert/containerops/containerops.key[log]filepath = log/containerops-log[db]uri = localhost:6379passwd = containeropsdb = 8[dockyard]path = datadomains = containerops.meregistry = 0.9distribution = registry/2.0standalone = true


2)安装及配置redis-server

apt-get update && apt-get install redis-server
打开/etc/redis/redis.conf配置文件,找到requirepass关键字(一般在330行),然后屏蔽这一行,在下一行添加requirepass containerops


3)编写Dockerfile,编译镜像

Dockerfile内容如下:

FROM ubuntu:latestMAINTAINER Yuzhilong <yuzhilong@chiasoftinc.com>RUN apt-get update --fix-missing && apt-get install -y --force-yes redis-serverCOPY dockyard /home/dockyardCOPY redis.conf /etc/redis/redis.confCOPY docker_bin /home/docker_binWORKDIR /home/dockyard#CMD service redis-server start && ./dockyard web --address=127.0.0.1 --port=5000CMD service redis-server start && ./dockyard web --address=0.0.0.0 --port=5000#CMD service redis-server start && ./dockyard web
编译镜像:docker build -t dockyard .

注意:此时Dockerfile文件是和dockyard目录处于同一级的。


三、测试镜像

1)启动容器:

docker run --rm -it --net=host dockyard

2)启动docker守护进程

 --insecure-registry containerops.me &
或者直接

docker daemon &

3)执行以下命令
docker pull containerops.me/mabin/busybox

注意:如果启动容器时没有指定--net=host则pull镜像时会出现以下错误:

Using default tag: latestPulling repository containerops.me/mabin/busyboxError while pulling image: Get http://containerops.me/v1/repositories/mabin/busybox/images: dial tcp 127.0.0.1:80: connection refused

三、在其它电脑的虚拟机上访问本机的容器服务

1)将两台电脑的虚拟机都设置为桥接模式

2)将客户端的/etc/hosts文件中的containerops.me修改为服务端的IP地址

3)启动服务端的容器,注意要将服务端的防火墙关闭





0 0