【发布时间】:2015-05-05 10:07:36
【问题描述】:
我在 github.com 上有一个私有 git 存储库,我想使用 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 是一个 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 在我的示例中工作?
【问题讨论】:
标签: docker dockerfile