如何链接Docker容器之间的二进制文件
是否有可能使用docker公开二进制从一个容器到另一个容器?
例如,我有2个容器:
- centos6
- SLES11
我需要这两个容器有类似的版本安装。 不幸的是,sles容器没有我需要的git版本。
我想旋转一个git容器,像这样:
$ cat Dockerfile FROM ubuntu:14.04 MAINTAINER spuder RUN apt-get update RUN apt-get install -yq git CMD /usr/bin/git # ENTRYPOINT ['/usr/bin/git']
然后将centos6和sles11容器连接到git容器,以便它们都可以访问git二进制文件,而不会经历安装它的麻烦。
我遇到了以下问题:
- 您无法将容器链接到另一个未运行的容器
- 我不确定这是否应该使用docker集装箱。
查看docker文档,看起来链接的容器具有共享的环境variables和端口,但不一定访问其他入口点。
我怎么能连接的git
容器,使分和容器可以访问此命令? 这可能吗?
您可以创build一个专用的git容器,并将其作为一个卷下载的数据公开,然后与另外两个容器(centos6和sles11)共享该卷。 即使容器未运行,卷也可用。
如果你希望其他两个容器能够从专用的git容器运行git
,那么你需要将git二进制文件安装(或复制)到共享卷上。
请注意,卷不是图像的一部分,所以当您执行docker save
或docker export
导出时,它们不会被保留或导出。 他们必须分开备份。
例
Dockerfile:
FROM ubuntu RUN apt-get update; apt-get install -y git VOLUME /gitdata WORKDIR /gitdata CMD git clone https://github.com/metalivedev/isawesome.git
然后运行:
$ docker build -t gitimage . # Create the data container, which automatically clones and exits $ docker run -v /gitdata --name gitcontainer gitimage Cloning into 'isawesome'... # This is just a generic container, but what I do in the shell # you could do in your centos6 container, for example $ docker run -it --rm --volumes-from gitcontainer ubuntu /bin/bash root@e01e351e3ba8:/# cd gitdata/ root@e01e351e3ba8:/gitdata# ls isawesome root@e01e351e3ba8:/gitdata# cd isawesome/ root@e01e351e3ba8:/gitdata/isawesome# ls Dockerfile README.md container.conf dotcloud.yml nginx.conf