我嘗試 dockerize 我的 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
但是在這之后什么都沒有,我做錯了什么?
uj5u.com熱心網友回復:
該EXPOSE宣告實際上并沒有做任何事情。它主要是一些關于您的容器偵聽的埠的檔案。在您的情況下,這是不正確的,因為 Nginx 默認偵聽埠 80。
運行容器時,應將埠 80 映射到要在主機上使用的埠。IE
docker run -d -p 4200:80 --rm <image name>
現在您應該可以通過 http://localhost:4200/ 訪問您的應用了
您應該洗掉 Dockerfile 中的 EXPOSE 陳述句,因為它會使以后查看您的 Dockerfile 的任何人感到困惑。
如果你真的想讓 Nginx 監聽埠 4200,你必須配置 Nginx 來做到這一點,但 IMO 不值得。讓它監聽 80 埠。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/461185.html
