compose icon indicating copy to clipboard operation
compose copied to clipboard

Add a no-cache option to docker-compose build

Open dkirrane opened this issue 11 years ago • 15 comments

It would be useful if one could do this docker-compose build service1 service2 --no-cache

dkirrane avatar Mar 02 '15 12:03 dkirrane

Just realized the syntax is docker-compose build --no-cache service1 service2

dkirrane avatar Mar 02 '15 12:03 dkirrane

I was looking for this !!

Here is my clean way to rebuild my compose stack

cd (to your compose DIR)

 docker-compose rm --all &&
 docker-compose pull &&
 docker-compose build --no-cache &&
 docker-compose up -d --force-recreate &&

Make sense? I'm looking for best practice here :)

pascalandy avatar Apr 20 '16 03:04 pascalandy

+1 Is the --force-recreate needed ?

lucj avatar Apr 27 '16 10:04 lucj

+1 I think --force-recreate is the best choice

pozgo avatar Aug 04 '16 08:08 pozgo

--force-recreate is unnecessary, because all containers have just been removed.

If you want to clear everything out, down is better than rm, because it can also remove volumes and networks.

$ docker-compose down -h
Stops containers and removes containers, networks, volumes, and images
created by `up`.

By default, the only things removed are:

- Containers for services defined in the Compose file
- Networks defined in the `networks` section of the Compose file
- The default network, if one is used

Networks and volumes defined as `external` are never removed.

Usage: down [options]

Options:
    --rmi type          Remove images. Type must be one of:
                        'all': Remove all images used by any service.
                        'local': Remove only images that don't have a custom tag
                        set by the `image` field.
    -v, --volumes       Remove named volumes declared in the `volumes` section
                        of the Compose file and anonymous volumes
                        attached to containers.
    --remove-orphans    Remove containers for services not defined in the
                        Compose file

aanand avatar Aug 04 '16 08:08 aanand

I'm using this since 3 months and it's rock solid for my needs. I don't want to remove: networks, volumes, and images


        echo && echo "PikWi says: docker-compose stop" && \
    docker-compose stop && \
        echo "PikWi says: docker-compose rm ..." && \
    docker-compose rm -f --all && \    
        echo "PikWi says: docker-compose pull" && \
    docker-compose pull && \
        echo "PikWi says: docker-compose build ..." && \
    docker-compose build --no-cache && \
        echo "PikWi says: docker-compose up ..." && \
    docker-compose up -d --force-recreate --remove-orphans

I'll be glad to use something shorter or cleaner. I'm all best practice :)

Cheers!

pascalandy avatar Aug 04 '16 13:08 pascalandy

--no-cache does not work.... what is the alternative --force-rebuild continues to use cache :(

julianfrank avatar Oct 25 '16 07:10 julianfrank

@julianfrank Not sure what you meant by --no-cache does not work but perhaps you run it as docker-compose build SERVICE_NAME --no-cache when it actually has to be docker-compose build --no-cache SERVICE_NAME?

maciej-gurban avatar Nov 28 '16 13:11 maciej-gurban

When the steps are same across the different services getting built, it still uses cache from the container just built earlier in the script...Worked out an alternative to use same steps when I want to use cache and change order to force skipping the cache usage...

julianfrank avatar Jan 08 '17 15:01 julianfrank

if you was fuc**d by the cache and instead using no cache you insert new commands in docker file to force renew cache layer send thumbs up, cache handling in docker needs a refactor... or works really cleaning the cache layers

gpgpublickey avatar Jan 25 '19 13:01 gpgpublickey

Indeed, it does not work... You can make all changes on a Dockerfile for a service, and there are no reflections on docker-compose build --no-cache

ivanleoncz avatar Apr 25 '19 18:04 ivanleoncz

docker-compose up -d --build --no-deps web will rebuild the container for the service named "web" in your docker-compose.yml. Once the rebuild is done, it will restart the specified container.

--no-deps will limit the rebuild to the name of the service specified in the command.

Additionally, this command will rebuild the container if you're copying files into the container and one of the files you copy in has changed - such as requirements.txt

mo18 avatar May 20 '19 21:05 mo18

FYI docker-compose up --force-recreate --build

There is apparently no --no-cache option for the up command Looks like force-recreate does not use this option. Please correct me if i am wrong!

So the best approach would be for me to do this...

Ultimate compose rebuild command for me

Removes container and images > builds images without build cache > docker-compose up detached > follow the logs (so you can ctrl+c out of it)

docker-compose build --force-rm --no-cache && docker-compose up --detach && docker-compose logs -f

Windows: docker-compose build --force-rm --no-cache ; docker-compose up --detach ; docker-compose logs -f

SimonGitter avatar Dec 05 '19 06:12 SimonGitter

Hello, I am fairly new to compose and was wondering if there is a "no-cache" option when working with compose files. I couldn't find anything related in the build support at https://github.com/compose-spec/compose-spec/blob/master/build.md

bowerth avatar Jan 02 '22 20:01 bowerth

I just tested this parameter and seems to work as follows:

build:
  no_cache: true

Fractal2017 avatar Dec 30 '23 17:12 Fractal2017