码头运行与包含变量的ENTRYPOINT [英] docker run with ENTRYPOINT containing a variable

查看:919
本文介绍了码头运行与包含变量的ENTRYPOINT的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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



从上一个问题中我发现如何将本地文件添加到图像中(称为上下文 Dockerfile): http://kimh.github我添加了一个简单的 $ /

我已经添加了一个简单的 src / hello_world.c 在repo中的示例,我想在 docker build 期间进行编译。见下文:



EDITED:添加 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-recommendations $ {PACKAGES}

ENV SEQTK https://github.com/avilella/seqtk/archive/sgdp.tar.gz

ENV THIRDPARTY_DIR $ {INSTALL_DIR} / thirdparty

运行mkdir -p $ {THIRDPARTY_DIR}
运行cd $ {THIRDPARTY_DIR}

#SEQTK

RUN mkdir -p $ {THIRDPARTY_DIR} / seqtk&& cd $ {THIRDPARTY_DIR} / seqtk&& \
wget --quiet --no-check-certificate $ {SEQTK} - 输出文档 - | \
tar xzf - 目录 。 --strip-components = 1&& \
make

#COMPILE HELLO_WORLD

添加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:没有这样的文件或目录2015/03/04 15:43:37来自守护进程的错误响应:无法启动容器cd39493be9f40a8714cbc1e503a1f172e2e5dc485881d0b5e34322fbb2f71380:exec:./hello_world:stat ./hello_world:没有这样的文件或目录

这样做:

  $ sudo docker run --entrypoint ='/ opt / foo / bar / hello_world'-i foo 
Hello World

任何想法如何使ENTRYPOINT在我的例如?

解决方案

ENTRYPOINT 不执行ENV替换,啊ref =http://docs.docker.com/reference/builder/#environment-replacement =nofollow> WORKDIR does

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆