我有一个angular 17项目,我想把它停靠.我已经构建了我的镜像,当我试图使用docker run -dit --name <container name> <imagename>运行容器时,容器立即退出.当我运行docker ps时,容器不会出现.

文档文件:

# Use node image as builder
FROM node:18.14 AS builder

# Set working directory in the container
WORKDIR /app

# Copy package.json and package-lock.json to the container
COPY package.json package-lock.json ./

# Install dependencies
RUN npm install

# Copy the rest of the application code
COPY . .

# Build the application
RUN npm run build --prod

# Use nginx image for serving the application
FROM nginx:latest

# Copy built application files from builder stage to nginx directory
COPY --from=builder /app/dist/project /usr/share/nginx/html

# Expose port 80 for nginx
EXPOSE 80

# Start nginx in foreground
CMD ["nginx", "-g", "daemon off;"]

我注意到我的图像无法在docker桌面中分析,如以下截图所示: Docker Desktop

推荐答案

正如你在 comments 中提到的exec /docker-entrypoint.sh: exec format error是真正需要解决的问题. 你能举一个最小的、可重复的例子吗?举个例子,这在我的本地工作

# Use node image as builder
FROM node:18.14 AS builder

# Set working directory in the container
WORKDIR /app

# (pretend to) Build the application
RUN echo "Hello world" > out.txt

# Use nginx image for serving the application
FROM nginx:latest

# Copy built application files from builder stage to nginx directory
COPY --from=builder /app/ /usr/share/nginx/html

这可能与处理器体系 struct 的差异有关,参见Docker Fails When Building on M1 Macs (exec /usr/local/bin/docker-entrypoint.sh: exec format error)https://docs.docker.com/build/guide/multi-platform/

如果您在本地构建映像并在其他地方运行,这可能是解决方案—https://stackoverflow.com/a/69636473/131391

如果您正在本地构建和运行,那么我首先要确保您可以在编写Dockerfile之前简单地运行上述基础映像.例如docker run nginx:latest

Angular相关问答推荐

Ionic 5角形共享两个模块之间的组件

Angular 空变量使用组件之间的共享服务

未在ng bootstrap 模式中设置表单输入

有Angular react 形式的输入用货币管

Angular :为什么我得到了一个可观察到的共鸣

天使17中的倒计时器

react 形式之间的循环关系

无法在单个元素上多次监听同一个事件

如何在 Angular RxJS 中替换订阅中的 subscrib?

nx workspace angular monorepo 在创建新应用程序时抛出错误

如果我使用 matAutocomplete,为什么 textarea 不显示 formControl 的实际值

如何从 RxJS 重试中排除某些 url

多个 Mat Paginator 在 Angular 组件中不起作用

不再需要 core-js 了吗?

无法获得 angular-material md-sidenav 的 100% 高度

Angular2订阅对子组件中@Input的更改

无法从模块it was neither declared nor imported导出服务

Angular 2中基于Condition条件的点击事件

如何使用 CLI 创建特定版本的 Angular 项目?

Hot and Cold observables:有 hot和 cold运算符吗?