首页 文章

docker-compose在哪里保留其图像?

提问于
浏览
0

我知道如果我改变我的 Dockerfile 或构建目录,我应该运行 docker-compose build . 这肯定意味着docker-compose在其已构建的图像的某处有一些缓存 .

它在哪里?我该如何清除它?

我想回到 docker-compose up 被迫做初始构建步骤的状态,而我不需要记得运行 docker-compose build .

我运行 docker stop $(docker ps -aq)docker X prune (对于容器,图像,卷,网络中的X),但 docker-compose up 仍然拒绝运行我的 Dockerfile 中的构建步骤 .

或者我完全误解了docker-compose的工作原理?

2 回答

  • 1

    docker-compose使用图像,您可以使用 docker images 查看:

    $ docker images 
    REPOSITORY                    TAG                 IMAGE ID            CREATED             SIZE
    docker_ubuntu                 latest              a7dc4f9bbdfb        19 hours ago        158MB
    ubuntu                        16.04               0b1edfbffd27        3 weeks ago         113MB
    hello-world                   latest              f2a91732366c        6 months ago        264MB
    

    docker-compose图像以(通常)您正在运行的目录的名称为前缀 docker-compose . 所以,对我来说, docker_ubuntu 图像 .

    docker image prune 认为图像正在使用中,因此它不会修剪它们 .

    要摆脱docker-compose图像,您需要显式删除它:

    docker image rm docker_ubuntu
    
  • 0

    您可以传递其他参数(--no-cache)以在构建过程中跳过使用缓存 .

    docker@default:~$ docker-compose build --help
        Build or rebuild services.
    
        Services are built once and then tagged as `project_service`,
        e.g. `composetest_db`. If you change a service's `Dockerfile` or the
        contents of its build directory, you can run `docker-compose build` to rebuild it.
    
        Usage: build [options] [--build-arg key=val...] [SERVICE...]
    
        Options:
            --compress              Compress the build context using gzip.
            --force-rm              Always remove intermediate containers.
            --no-cache              Do not use cache when building the image.
            --pull                  Always attempt to pull a newer version of the image.
            -m, --memory MEM        Sets memory limit for the build container.
            --build-arg key=val     Set build-time variables for services.
        docker@default:~$
    

相关问题