码头运行与包含变量的ENTRYPOINT [英] docker run with ENTRYPOINT containing a variable
问题描述
我在 github.com 上有一个私有git存储库,我想自动化 docker build
使用 Dockerfile
进程。我天真地认为最好的地方是把$ code> Dockerfile 在我的repo的根文件夹中。例如:
git clone ssh://git@github.com/avilella/bioboxes_playground
cd bioboxes_playground
ls Dockerfile
Dockerfile
所以repo文件夹中的文件是:
[hpenvy15 bioboxes_playground] $ tree -Difts
。
[18027 3月3日14:58] ./LICENSE
[3月3日3日14:58] ./README.md
[825 3月4日11:59] ./Dockerfile
[4096 Mar 4 11:59] ./src
[74 3月4日11:59] ./src/hello_world.c
所以对于外部依赖关系,我使用 apt-get install
安装它们,或者下载tar.gz并在 docker build
。
WORKDIR $ {INSTALL_DIR}
ENTRYPOINT ./hello_world
但是我想知道你为什么要把INSTALL_DIR作为一个变量?如果您没有使用容器,您可以这样做,以便 / opt / foo / bar
和 / opt / foo / baz
和 / opt / qux / bar
都可以共存。但是,如果这些都是在一个单独的容器中,那么它们都可以生活在 / opt / app
。
I have a private git repository on github.com and I want to automate the docker build
process using a Dockerfile
. I naively thought the best place to have the Dockerfile
is in the root folder of my repo. Example:
git clone ssh://git@github.com/avilella/bioboxes_playground
cd bioboxes_playground
ls Dockerfile
Dockerfile
So the files in the repo folder are:
[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
So for external dependencies, I am installing them with apt-get install
or downloading the tar.gz and installing them during docker build
.
I found out from a previous question how to add local files to the image (called the "context" in Dockerfile): http://kimh.github.io/blog/en/docker/gotchas-in-writing-dockerfile-en/#add_and_understanding_context_in_dockerfile
I added a simple src/hello_world.c
example which is in the repo, and I want to compile during docker build
. See below:
EDITED: added WORKDIR
now
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"]
My issue currently is that my defined ENTRYPOINT
does not work
because INSTALL_DIR
is an ENV variable. I can hard-code it to
/opt/foo/bar/hello_world
, and then it works:
$ 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
This works:
$ sudo docker run --entrypoint='/opt/foo/bar/hello_world' -i foo
Hello World
Any ideas how to make the ENTRYPOINT work in my example?
ENTRYPOINT
doesn't do ENV replacement, but WORKDIR
does:
WORKDIR ${INSTALL_DIR}
ENTRYPOINT ./hello_world
But I wonder why you want to have the INSTALL_DIR as a variable? If you weren't using containers, you'd do this so that /opt/foo/bar
and /opt/foo/baz
and /opt/qux/bar
can all coexist. But if each of these is in a separate container, then they can all live at /opt/app
.
这篇关于码头运行与包含变量的ENTRYPOINT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!