docker运行包含一个variables的ENTRYPOINT
我有一个github.com上的私人git存储库,我想使用Dockerfile
自动化Dockerfile
docker build
过程。 我天真地以为Dockerfile
是在我的回购站的根文件夹中的最佳位置。 例:
git clone ssh://git@github.com/avilella/bioboxes_playground cd bioboxes_playground ls Dockerfile Dockerfile
所以repo文件夹中的文件是:
[hpenvy15 bioboxes_playground] $ tree -Difts . [ 18027 Mar 3 14:58] ./LICENSE [ 22 Mar 3 14:58] ./README.md [ 825 Mar 4 11:59] ./Dockerfile [ 4096 Mar 4 11:59] ./src [ 74 Mar 4 11:59] ./src/hello_world.c
所以对于外部依赖,我正在安装apt-get install
或者下载tar.gz并在docker build
期间安装它们。
我从前面的问题中发现如何将本地文件添加到图像中(称为Dockerfile中的“上下文”): http ://kimh.github.io/blog/en/docker/gotchas-in-writing-dockerfile-en /#add_and_understanding_context_in_dockerfile
我在repo中添加了一个简单的src/hello_world.c
示例,并且我想在docker build
期间进行编译。 见下文:
编辑:现在增加了WORKDIR
FROM debian:wheezy MAINTAINER Foo Bar, foo@bar.com ENV ORG foo ENV APP bar ENV INSTALL_DIR /opt/${ORG}/${APP} ENV PACKAGES wget binutils make csh g++ sed gawk perl zlib1g-dev RUN apt-get update -y && apt-get install -y --no-install-recommends ${PACKAGES} ENV SEQTK https://github.com/avilella/seqtk/archive/sgdp.tar.gz ENV THIRDPARTY_DIR ${INSTALL_DIR}/thirdparty RUN mkdir -p ${THIRDPARTY_DIR} RUN cd ${THIRDPARTY_DIR} # SEQTK RUN mkdir -p ${THIRDPARTY_DIR}/seqtk && cd ${THIRDPARTY_DIR}/seqtk &&\ wget --quiet --no-check-certificate ${SEQTK} --output-document - |\ tar xzf - --directory . --strip-components=1 && \ make # COMPILE HELLO_WORLD ADD src/hello_world.c ${INSTALL_DIR}/hello_world.c RUN gcc ${INSTALL_DIR}/hello_world.c -o ${INSTALL_DIR}/hello_world WORKDIR ${INSTALL_DIR} ENTRYPOINT ["./hello_world"]
我目前的问题是我定义的ENTRYPOINT
不起作用,因为INSTALL_DIR
是一个ENVvariables。 我可以将其硬编码到/opt/foo/bar/hello_world
,然后运行:
$ sudo docker run -i foo exec: "./hello_world": stat ./hello_world: no such file or directory2015/03/04 15:43:37 Error response from daemon: Cannot start container cd39493be9f40a8714cbc1e503a1f172e2e5dc485881d0b5e34322fbb2f71380: exec: "./hello_world": stat ./hello_world: no such file or directory
这工作:
$ sudo docker run --entrypoint='/opt/foo/bar/hello_world' -i foo Hello World
任何想法如何使我的例子中的ENTRYPOINT工作?
ENTRYPOINT
不会执行ENV更换,但WORKDIR
执行以下操作 :
WORKDIR ${INSTALL_DIR} ENTRYPOINT ./hello_world
但是我想知道你为什么要把INSTALL_DIR作为一个variables? 如果您不使用容器,那么可以这样做,以便/opt/foo/bar
和/opt/foo/baz
和/opt/qux/bar
都可以共存。 但是,如果每个都在一个单独的容器中,那么它们都可以在/opt/app
生存。