英文:
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="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 #here
RUN go mod download
COPY . .
RUN go install ./...
CMD ["dkron"]
It also has dockerfile.hub which contains this
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"]
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 <src> and adds them to the filesystem of the container at the path <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 . .
。
文档中的重要链接:
- 复制步骤:https://docs.docker.com/engine/reference/builder/#copy
- 构建上下文:https://docs.docker.com/engine/reference/builder/#usage
英文:
> 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:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论