OpenShift 3.1 – Prevent Docker from caching curl resource

I have this curl command in my Dockerfile:

RUN curl -H 'Cache-Control: no-cache' -f ${NEXUS_URL}${ARTIFACT_PATH}-${ARTIFACT_VERSION}.war?nocache=true -o $JBOSS_HOME/standalone/deployments/ROOT.war

The first time I ran it I could see the download information. However after that it seems to be caching the remote resource and thus, not updating it anymore:

  • Running Lua script in Docker
  • How to find out all the images which are created by performing commit on the particular container?
  • Why is my Tutum service starting then within 2 seconds stopping with a container status “die” command?
  • Connection Failing to Docker Container
  • Build docker image from local instead of git clone
  • Docker list only stopped containers
  • Step 6 : RUN curl -H 'Cache-Control: no-cache' -f ${NEXUS_URL}${ARTIFACT_PATH}-${ARTIFACT_VERSION}.war?nocache=true -o $JBOSS_HOME/standalone/deployments/ROOT.war
    30   ---> Using cache
    31   ---> be50412bf6c3
    

    How could I prevent this?

  • From inside of a Docker container, how do I connect to the localhost of the machine?
  • Persistence of Docker Data Containers
  • How to install nvm in a Dockerfile?
  • Trouble running UPNP on Docker
  • Clone server to docker image
  • Is it better to build and test in a container?
  • 3 Solutions collect form web for “OpenShift 3.1 – Prevent Docker from caching curl resource”

    According to the OpenShift docs (https://docs.openshift.com/enterprise/3.1/dev_guide/builds.html#no-cache) you can force builds to not be cached using the following syntax:

    strategy:
      type: "Docker"
      dockerStrategy:
        noCache: true
    

    This will mean that no steps are cached, which will make your builds slower but will mean you have the correct artifact version in your build.

    You can bust the cache at a specific Dockerfile instruction using ARG.

    In the Dockerfile:

    ARG CACHEBUST=1
    RUN git clone https://github.com/octocat/Hello-World.git 
    

    On the command line:

    docker build -t your-image --build-arg CACHEBUST=$(date +%s) . 
    

    Setting CACHEBUST to the current time means that it will always be
    unique, and instructions after the ARG declaration in the Dockerfile
    won’t be cached. Note that you can also build without specifying the
    CACHEBUST build-arg, which will cause it to use the default value of 1
    and preserve the cache. This can be used to always check out fresh
    copies of git repos, pull latest SNAPSHOT dependencies, etc.

    Source

    Also:

    You can use –no-cache, or –build-arg to invalidate the cache. You
    can minimize the effect of –no-cache by having a base image with all
    the cacheable commands.

    Source

    I can’t control the way docker is run, I mean I am running in a PaaS that calls my dockerfile so I can’t pass arguments in docker build

    You could try and control the content of your Dockerfile though.

    If you can re-generate the Dockerfile before letting the PaaS calling it, that would help making sure the cache is invalidated:

    sed -i 's/ROOT.war.*/ROOT.war && echo $(date)'/g' Dockerfile
    
    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.