我有一个 Dockerfile 和 Docker composefile,如下所示。
我的 Dockerfile
FROM ubuntu:22.04 as build-deps
RUN apt-get update \
&& apt install -y nodejs \
&& apt install -y npm
COPY . /opt/mlops
WORKDIR /opt/mlops
RUN npm i && npm i chart.js
#CMD ["npm", "start"]
RUN npm run build
FROM nginx:stable
COPY --from=build-deps /opt/mlops/build /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
我的 Docker 撰写文件
version: '2'
services:
frontend:
build: .
image: front:1.0
ports:
- "80:80"
volumes:
- frontend:/usr/share/nginx/html
networks:
- mlops
volumes:
frontend:
networks:
mlops:
我面临的问题是,即使删除所有图像并再次构建后,我也无法检测到容器中运行的网站上的更改。
我能够运行该网站。
这是一个nodejs应用程序。
我尝试使用
docker compose build
命令,然后使用 docker system prune --all
清除所有内容,然后运行 docker compose up -d
但不幸的是它仍然没有更新
你这里有一个 docker 卷
volumes:
- frontend:/usr/share/nginx/html
首次创建卷时,如果该卷映射的映像中有任何内容,则该内容将复制到该卷(请参阅 https://docs.docker.com/storage/volumes/#populate-a -使用容器的体积)。第一次运行容器时会发生这种情况。在所有后续运行中,卷中已经存在某些内容,因此您拥有的新内容不会复制到卷中。这就是为什么您不断看到旧内容。
我不明白拥有这个卷的意义,我会删除 docker-compose 文件中的这两行。之后,您应该会看到更新后的映像的内容(在停止容器并启动新容器之后)。
这对我有用
version: '3.8'
services:
api_app:
build:
context: ./ # Path to the directory containing the Dockerfile
dockerfile: Dockerfile # Name of the Dockerfile
ports:
- "8080:8080" # Map port 8080 on the host to port 8080 in the container
volumes:
- .:/var/www/api # Mount the current directory to /var/www/legacy in the container
environment:
- APACHE_RUN_USER=${APACHE_RUN_USER}
- APACHE_RUN_GROUP=${APACHE_RUN_GROUP}
- APACHE_LOG_DIR=${APACHE_LOG_DIR}
- APP_NAME=GPUBackend
- APP_ENV=${APP_ENV}
- APP_KEY=${APP_KEY}
restart: unless-stopped # Automatically restart the container unless it's stopped
networks:
- api_network # Use a custom network (optional)
networks:
api_network:
driver: bridge # Use the default bridge network