需要在Dockerfile中对命令进行澄清吗?

huangapple go评论70阅读模式
英文:

Need clarification on command in Dockerfile?

问题

以下是翻译好的内容:

我正尝试通过开源的Dkron调度器运行jar文件。我需要修改Docker文件以在容器中安装Java。请为我解释一下这里的COPY命令是什么意思:

FROM golang:1.14
LABEL maintainer="Victor Castell <victor@victorcastell.com>"

EXPOSE 8080 8946

RUN mkdir -p /app
WORKDIR /app

ENV GO111MODULE=on
COPY go.mod go.mod
COPY go.sum go.sum            #这里
RUN go mod download

COPY . .
RUN go install ./...

CMD ["dkron"]

它还有一个名为dockerfile.hub的文件,其中包含以下内容:

FROM alpine
MAINTAINER Victor Castell <victor@victorcastell.com>

ENV DKRON_VERSION 0.11.0

RUN set -x \
    && buildDeps='bash ca-certificates openssl' \
    && apk add --update $buildDeps \
    && rm -rf /var/cache/apk/* \
    && mkdir -p /opt/local/dkron \
    && wget -O /opt/local/dkron/dkron.tar.gz https://github.com/victorcoder/dkron/releases/download/v${DKRON_VERSION}/dkron_${DKRON_VERSION}_linux_amd64.tar.gz \
    && cd /opt/local/dkron \
    && tar -xzf dkron.tar.gz \
    && rm /opt/local/dkron/dkron.tar.gz

EXPOSE 8080 8946

ENV SHELL /bin/bash
WORKDIR /opt/local/dkron

ENTRYPOINT ["/opt/local/dkron/dkron"]

CMD ["--help"]

此外,要使Java文件在容器中运行,需要进行哪些更改?谢谢。

英文:

I am trying to run jar file through open source Dkron scheduler. I am need to modify docker file to install java in container. Please clarify me what copy command means here

FROM golang:1.14
LABEL maintainer=&quot;Victor Castell &lt;victor@victorcastell.com&gt;&quot;

EXPOSE 8080 8946

RUN mkdir -p /app
WORKDIR /app

ENV GO111MODULE=on
COPY go.mod go.mod
COPY go.sum go.sum            #here
RUN go mod download

COPY . .
RUN go install ./...

CMD [&quot;dkron&quot;]

It also has dockerfile.hub which contains this

FROM alpine
MAINTAINER Victor Castell &lt;victor@victorcastell.com&gt;

ENV DKRON_VERSION 0.11.0

RUN set -x \
	&amp;&amp; buildDeps=&#39;bash ca-certificates openssl&#39; \
	&amp;&amp; apk add --update $buildDeps \
	&amp;&amp; rm -rf /var/cache/apk/* \
	&amp;&amp; mkdir -p /opt/local/dkron \
	&amp;&amp; wget -O /opt/local/dkron/dkron.tar.gz https://github.com/victorcoder/dkron/releases/download/v${DKRON_VERSION}/dkron_${DKRON_VERSION}_linux_amd64.tar.gz \
	&amp;&amp; cd /opt/local/dkron \
	&amp;&amp; tar -xzf dkron.tar.gz \
	&amp;&amp; rm /opt/local/dkron/dkron.tar.gz

EXPOSE 8080 8946

ENV SHELL /bin/bash
WORKDIR /opt/local/dkron

ENTRYPOINT [&quot;/opt/local/dkron/dkron&quot;]

CMD [&quot;--help&quot;]

Also what changes need to be done to make java file run in the container? Thank you.

答案1

得分: 1

"COPY指令将新文件或目录从复制并将它们添加到容器的文件系统中,路径为。"

这是来自Docker文档的内容:https://docs.docker.com/engine/reference/builder/

英文:

> The COPY instruction copies new files or directories from &lt;src> and adds them to the filesystem of the container at the path &lt;dest>.

this is from the Docker documentation: https://docs.docker.com/engine/reference/builder/

答案2

得分: 0

请向我解释一下这里的 copy 命令是什么意思。

...

COPY . .

复制步骤会从构建上下文中获取文件,并将它们复制到生成的镜像的一个层中。构建上下文是从客户端传递给 Docker 引擎的构建命令中的一个参数,通常是 .,表示当前目录作为构建上下文发送。

在多阶段构建过程中,您可以将源更改为另一个阶段,从而允许您将构建生成物从编译器环境传输到要部署的运行时环境。您还可以将其更改为从另一个镜像中拉取文件。这两者都是通过复制步骤的 --from 选项来完成的。

请注意,此命令仅单向工作,目标始终是您正在构建的镜像。由于源在历史上始终是构建上下文,因此在语法中不包括源和目标的范围。例如,Docker 将 COPY build-context:. container:. 简化为 COPY . .

文档中的重要链接:

英文:

> Please clarify me what copy command means here
> ...
>
> COPY . .

The copy step takes files from the build context and copies them into a layer of the resulting image. The build context is passed from the client to the docker engine as the one arg in the build command, typically a . to indicate the current directory is sent as the build context.

You can change the source to be another stage during a multi-stage build, allowing you to transfer build artifacts from a compiler environment to a runtime environment you wish to deploy. And you can change it to pull files from another image. Both of these are done with the --from option to the copy step.

Note that this command only works one way, the destination is always the image you are building, and since the source was historically always the build context, the scope on the source and destination are not included in the syntax. E.g. docker shortened COPY build-context:. container:. to just COPY . ..

Important links in the documention:

huangapple
  • 本文由 发表于 2020年9月19日 21:06:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/63969150.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定