How to force Docker for a clean build of an image

后端 未结 9 933
情书的邮戳
情书的邮戳 2021-01-29 17:12

I have build a Docker image from a Docker file using the below command.

$ docker build -t u12_core -f u12_core .

When I am trying to rebuild it

相关标签:
9条回答
  • 2021-01-29 17:44

    The command docker build --no-cache . solved our similar problem.

    Our Dockerfile was:

    RUN apt-get update
    RUN apt-get -y install php5-fpm
    

    But should have been:

    RUN apt-get update && apt-get -y install php5-fpm
    

    To prevent caching the update and install separately.

    See: Best practices for writing Dockerfiles

    0 讨论(0)
  • 2021-01-29 17:46

    In some extreme cases, your only way around recurring build failures is by running:

    docker system prune
    

    The command will ask you for your confirmation:

    WARNING! This will remove:
        - all stopped containers
        - all volumes not used by at least one container
        - all networks not used by at least one container
        - all images without at least one container associated to them
    Are you sure you want to continue? [y/N]
    

    This is of course not a direct answer to the question, but might save some lives... It did save mine.

    0 讨论(0)
  • 2021-01-29 17:52

    To ensure that your build is completely rebuild, including checking the base image for updates, use the following options when building:

    --no-cache - This will force rebuilding of layers already available

    --pull - This will trigger a pull of the base image referenced using FROM ensuring you got the latest version.

    The full command will therefore look like this:

    docker build --pull --no-cache --tag myimage:version .
    

    Same options are available for docker-compose:

    docker-compose build --no-cache --pull
    

    Note that if your docker-compose file references an image, the --pull option will not actually pull the image if there is one already.

    To force docker-compose to re-pull this, you can run:

    docker-compose pull
    
    0 讨论(0)
提交回复
热议问题