Xubuntu [SOLVED]: Previous apt-get update & install Docker layer removed during every build

Xubuntu [SOLVED]: Previous apt-get update & install Docker layer removed during every build

Home Forums Xubuntu Xubuntu [SOLVED]: Previous apt-get update & install Docker layer removed during every build

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #36871

    Anonymous

    QuestionQuestion

    I have a Dockerfile containing the following:

    FROM ubuntu:17.10
    WORKDIR /app
    ADD . /app
    RUN apt-get update && apt-get install -y 
    python3-pip 
    python3-numpy 
    ffmpeg 
    python3.6 
    xz-utils
    ...
    

    The layer created at the RUN statement is removed every time I run docker build and I’m not sure why this is the case. Installing all the dependencies takes a long time, so I’d like for Docker to cache that layer and use it again in the future.

    What can I do to get that behaviour?

    Thank you.

    #36872

    Anonymous

    Accepted AnswerAnswer

    As per documentation, if one layer’s cache is invalidated, subsequent layer will need to be re-built. Hence, it’s best practice to have all static steps first in Dockerfile (e.g. in your case, you can move RUN apt-get ... command up). Hope it clear

    For the ADD and COPY instructions, the contents of the file(s) in the
    image are examined and a checksum is calculated for each file. The
    last-modified and last-accessed times of the file(s) are not
    considered in these checksums. During the cache lookup, the checksum
    is compared against the checksum in the existing images. If anything
    has changed in the file(s), such as the contents and metadata, then
    the cache is invalidated.

    Once the cache is invalidated, all subsequent Dockerfile commands will
    generate new images and the cache will not be used.

    Source: https://stackoverflow.com/questions/48029756/previous-apt-get-update-install-docker-layer-removed-during-every-build
    Author: Apolozeus
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.