我的目录结构:
??? src/
?????? backend/
???????? Dockerfile
???????? ...
?????? frontend/
???????? Dockerfile
???????? node_modules/
???????? ...
?????? commons/
???????? ...
??? .dockerignore
Run Code Online (Sandbox Code Playgroud)
.dockerignore包括行**/node_modules和我的构建上下文的根目录是由于使用commons。
我两个都跑
docker build ... -f src/backend/Dockerfile .
docker build ... -f src/frontend/Dockerfile .
并行,有时backend构建会因以下特定错误而失败:
错误检查上下文:“文件 ('/workspace/src/frontend/node_modules/.staging/wrap-ansi-2a6f888f') 未找到或被 .dockerignore 排除”。
根据我的理解(请参阅为什么 Node 模块会进入 .staging 文件夹?)该.staging文件夹是临时的,并且在运行它时可能存在竞争条件(请参阅 Docker cli源代码)。
但是,如果node_modules忽略这个文件,为什么首先会走呢?我是在滥用忽略上下文功能还是实际的竞争条件?
该问题在 Google Cloud Build 环境中重现,其中我通过图像使用 docker cli,该图像gcr.io/cloud-builders/docker使用 docker 客户端版本19.03.5并使用 docker …
我有几个不属于我的基础docker图像(所以我不能修改它们).但是,我正在创建新的图像,并安装了其他内容.
我无法弄清楚的是如何告诉dockerfile复制基本图像的CMD(或ENTRYPOINT).像这样的东西:
FROM other:latest
RUN my-extra-install
CMD <use-the-CMD-from-base-image>
Run Code Online (Sandbox Code Playgroud)
我不认为CMD命令有任何直接的语法来做我想要的.我想知道是否有解决方法.
文件
FROM node:alpine
COPY ./ ./
RUN npm install
CMD ["npm", "start"]
Run Code Online (Sandbox Code Playgroud)
索引.js
const express = require('express');
const app = express();
app.get('/', (req, res) => {
res.send('Hi there');
});
app.listen(8080, () => {
console.log("Listening on post 8080");
});
Run Code Online (Sandbox Code Playgroud)
包.json
{
"dependencies": {
"express": "*"
},
"scripts": {
"start": "node index.js"
}
}
Run Code Online (Sandbox Code Playgroud)
码头工人建造。
npm ERR! could not detect node name from path or package
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-11-23T23_36_35_301Z-debug.log
The …Run Code Online (Sandbox Code Playgroud) 更新:这个问题是用 MVRE 重构的。
\n有没有办法可以RUN从使用 构建的 Dockerfile 中查看完整命令docker build?\n例如 如果我的 Dockerfile 有这样的语句:
# Dockerfile\nFROM alpine:3.7 as base\nRUN echo "this is the song that doesn\'t end. Yes it goes on and on, my friends. Some people started singing it not knowing what it was, and they\'ll continue singing it forever just because..."\nRun Code Online (Sandbox Code Playgroud)\n...有没有办法可以看到完整的命令,即echo "this is the song that doesn\'t end. Yes it goes on and on, my friends. Some people started singing …
如何docker build从Dockerfile更多的内存?
这是一个与此不同的问题当docker构建Dockerfile时允许更多内存
在本机安装软件时,有足够的内存来成功构建和安装该marian工具
但是当使用Dockerfile
https://github.com/marian-nmt/marian/blob/master/scripts/docker/Dockerfile.cpu构建Docker镜像时,它会因多个内存耗尽错误而失败
virtual memory exhausted: Cannot allocate memory
Run Code Online (Sandbox Code Playgroud)
[OUT]:
Step : RUN cmake $MARIANPATH && make -j
---> Running in 4867d166d17a
-- The C compiler identification is GNU 5.4.0
-- The CXX compiler identification is GNU 5.4.0
-- Check for working C compiler: /usr/bin/cc
-- Check for working C compiler: /usr/bin/cc -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting …Run Code Online (Sandbox Code Playgroud) 我正在构建一个 Dockerfile,我想在构建它时显示一些帮助消息。
我也尝试过,RUN echo "installing this"但正如预期的那样,它不起作用。
那么,如何docker build在安静模式下运行命令时显示帮助消息以及如果可能的话。
我正在尝试使用docker镜像运行我的ASP.NET Core 2.1应用程序.为此我有docker文件,其中包含以下内容:
FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /app
# copy csproj and restore as distinct layers
COPY . .
RUN dotnet restore
# copy everything else and build app
COPY Presentation/MyProject.Web/. ./Presentation/MyProject.Web/
WORKDIR /app/Presentation/MyProject.Web
RUN dotnet publish -c Release -o out
# Build runtime image
FROM microsoft/dotnet:aspnetcore-runtime
WORKDIR /app
COPY --from=build /app/Presentation/MyProject.Web/out .
ENTRYPOINT ["dotnet", "MyProject.Web.dll"]
Run Code Online (Sandbox Code Playgroud)
但是当执行命令时docker build -t MyProject-web .它会给我一个错误:
The command '/bin/sh -c dotnet publish -c Release -o out' returned a non-zero code: 1
MyProject.Web …Run Code Online (Sandbox Code Playgroud) 我正在尝试从 docker 容器中获取 Maven 离线构建。我已经启用了 buildkit。我已经运行mvn dependency:go-offline -s ~/checkouts/settings.xml以缓存/root/.m2主机的依赖项。我希望在构建 maven 项目的容器中使用它。
这是我的 Dockerfile:
#syntax=docker/dockerfile:experimental
FROM maven:3.6.1-jdk-11 AS build
WORKDIR /
COPY . /
RUN --mount=type=cache,target=/root/.m2 mvn -o install
FROM scratch
COPY --from=build /admin/admin-
rest/target/admin-rest.war /webapps/ROOT.war
Run Code Online (Sandbox Code Playgroud)
当我尝试使用docker build此 Dockerfile 时,出现以下错误:
插件 org.codehaus.mojo:build-helper-maven-plugin:3.0.0 或其依赖项之一无法解析:无法在离线模式下访问中心 ( https://repo.maven.apache.org/maven2 ) 和工件 org.codehaus.mojo:build-helper-maven-plugin:jar:3.0.0 之前没有从它下载。-> [帮助 1]
我的 Docker 版本:
Client:
Version: 18.09.6
API version: 1.39
Go version: go1.10.8
Git commit: 481bc77
Built: Sat May 4 02:35:57 2019
OS/Arch: linux/amd64
Experimental: …Run Code Online (Sandbox Code Playgroud) 我正在学习如何在 Dockerfiles 中使用 ARG 和 ENV。我有这个简单的 Dockerfile:
ARG my_arg
ARG other_arg=other_default
FROM centos:7
ENV MY_ENV $my_arg
ENV OTHER_ENV $other_arg
CMD echo "$MY_ENV $OTHER_ENV"
Run Code Online (Sandbox Code Playgroud)
当我构建它时:
docker build --build-arg my_arg=my_value
并运行它:
docker run <resulting-image>
我没有看到预期的输出,这将是
my_value other_default
Run Code Online (Sandbox Code Playgroud)
相反,我看到的是空字符串。我究竟做错了什么?
在Windows 的Docker 桌面中构建我的 docker 映像时,一段时间后它抛出错误:
=> => # [输出被裁剪,日志限制达到 1MiB]
我厌倦了在守护程序文件中配置日志文件大小并重新启动了docker服务
"log-driver": "json-file",
"log-opts":
{
"max-size": "10m",
"max-file": "3"
}
Run Code Online (Sandbox Code Playgroud)
但是我仍然遇到同样的错误,有人请告诉我吗?
docker ×10
docker-build ×10
dockerfile ×4
asp.net-core ×1
c# ×1
docker-image ×1
logging ×1
maven ×1
memory ×1
neural-mt ×1
node-modules ×1