我有一个私人 git 存储库github.com http://github.com我想自动化docker build
过程使用Dockerfile
。我天真地认为最好的地方Dockerfile
位于我的存储库的根文件夹中。例子:
git clone ssh://[email protected] /cdn-cgi/l/email-protection/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 http://kimh.github.io/blog/en/docker/gotchas-in-writing-dockerfile-en/#add_and_understanding_context_in_dockerfile
我添加了一个简单的src/hello_world.c
存储库中的示例,我想在期间进行编译docker build
。见下文:
编辑:添加WORKDIR
now
FROM debian:wheezy
MAINTAINER Foo Bar, [email protected] /cdn-cgi/l/email-protection
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
是一个 ENV 变量。我可以将其硬编码为/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 在我的示例中起作用吗?