Dockerfile和docker-不使用新指令进行更新

Leo*_*eon 8 containers docker dockerfile docker-compose

当我尝试使用docker-compose构建容器时

nginx:
  build: ./nginx
  ports:
    - "5000:80"
Run Code Online (Sandbox Code Playgroud)

当我的Dockerfile看起来像这样时,COPY指令不起作用

FROM nginx

#Expose port 80
EXPOSE 80

COPY html /usr/share/nginx/test

#Start nginx server
RUN service nginx restart
Run Code Online (Sandbox Code Playgroud)

可能是什么问题呢?

Leo*_*eon 26

似乎在使用docker-compose命令时,它会保存一个中间容器,它不会向您显示并不断重新运行,从而无法正确更新它.可悲的是,关于这样的事情的文件很差.解决这个问题的方法是首先构建它,没有缓存,然后像这样建立它

docker-compose build --no-cache
docker-compose up -d
Run Code Online (Sandbox Code Playgroud)

  • 是的,它需要修复,请参阅 https://github.com/docker/compose/issues/693 和 https://github.com/docker/compose/issues/12 (3认同)
  • 对于非组合容器:“docker build --no-cache”。 (2认同)

Phi*_*ger 22

我遇到了同样的问题,为我做的一个衬里是:

docker-compose up --build --remove-orphans --force-recreate

  • --build完成工作的最大部分并触发构建。
  • --remove-orphans如果您更改了其中一项服务的名称,此选项很有用。否则,您可能会收到一条剩余的警告,告诉您有关旧的、现在错误命名的服务悬而未决的情况。
  • --force-recreate有点激烈,但会强制重新创建容器。

参考: https: //docs.docker.com/compose/reference/up/

警告我可以在我的项目中执行此操作,因为我正在研究非常小的容器图像。每次重新创建所有内容可能会花费大量时间,具体取决于您的情况。