是否可以使用docker将二进制文件从一个容器暴露给另一个容器?
例如,我有2个容器:
我需要这两个容器都安装了类似的git版本.不幸的是,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']
Run Code Online (Sandbox Code Playgroud)
然后将centos6和sles11容器链接到git容器,以便它们都可以访问git二进制文件,而无需安装它.
我遇到了以下问题:
查看docker文档,看起来链接容器具有共享环境变量和端口,但不一定访问彼此的入口点.
我如何链接git容器,以便分和容器可以访问此命令?这可能吗?
您可以创建一个专用的 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
Run Code Online (Sandbox Code Playgroud)
然后运行:
$ 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1804 次 |
| 最近记录: |