Dockerize 一个 angular Cli 应用程序但没有附加任何内容

Dockerize an angular Cli app but nothing append

我尝试 docker 化我的 angular 应用程序,所以我制作了一个 Dockerfile :

FROM teracy/angular-cli as angular-built
WORKDIR /usr/src/app
COPY package.json package.json
RUN npm install
COPY . .
RUN ng build

FROM nginx:alpine
LABEL author="pleijan"
COPY --from=angular-built /usr/src/app/dist /usr/share/nginx/html

EXPOSE 4200

它可以构建,但是当我 运行 它在 docker 桌面上时,这就是发生的事情:

/docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration
/docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/
/docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh
10-listen-on-ipv6-by-default.sh: info: Getting the checksum of etc/nginx/conf.d/default.conf
10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf
/docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh
/docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh
/docker-entrypoint.sh: Configuration complete; ready for start up
2022/04/21 18:09:40 [notice] 1#1: using the "epoll" event method
2022/04/21 18:09:40 [notice] 1#1: nginx/1.21.6
2022/04/21 18:09:40 [notice] 1#1: built by gcc 10.3.1 20211027 (Alpine 10.3.1_git20211027) 
2022/04/21 18:09:40 [notice] 1#1: OS: Linux 5.10.102.1-microsoft-standard-WSL2
2022/04/21 18:09:40 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576
2022/04/21 18:09:40 [notice] 1#1: start worker processes
2022/04/21 18:09:40 [notice] 1#1: start worker process 33
2022/04/21 18:09:40 [notice] 1#1: start worker process 34
2022/04/21 18:09:40 [notice] 1#1: start worker process 35
2022/04/21 18:09:40 [notice] 1#1: start worker process 36

但是在这之后什么都没有附加,我做错了什么?

EXPOSE 语句实际上没有做任何事情。它主要是关于您的容器侦听哪个端口的一些文档。在您的情况下,这是不正确的,因为 Nginx 默认侦听端口 80。

当你运行容器时,你应该将端口80映射到你想在主机上使用的端口。即

docker run -d -p 4200:80 --rm <image name>

现在您应该可以通过 http://localhost:4200/

访问您的应用程序

您应该删除 Dockerfile 中的 EXPOSE 语句,因为它会使以后查看您的 Dockerfile 的任何人感到困惑。

如果你真的想让 Nginx 监听 4200 端口,你必须配置 Nginx 来做到这一点,但我认为这是不值得的。让它在端口 80 上监听。