Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a no-cache option to docker-compose build #1049

Closed
dkirrane opened this issue Mar 2, 2015 · 12 comments

Comments

@dkirrane
Copy link

commented Mar 2, 2015

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

@dkirrane

This comment has been minimized.

Copy link
Author

commented Mar 2, 2015

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

@dkirrane dkirrane closed this Mar 2, 2015
@pascalandy

This comment has been minimized.

Copy link

commented Apr 20, 2016

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 :)

@lucj

This comment has been minimized.

Copy link

commented Apr 27, 2016

+1
Is the --force-recreate needed ?

@pozgo

This comment has been minimized.

Copy link

commented Aug 4, 2016

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

@aanand

This comment has been minimized.

Copy link
Contributor

commented Aug 4, 2016

--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
@pascalandy

This comment has been minimized.

Copy link

commented Aug 4, 2016

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!

@julianfrank

This comment has been minimized.

Copy link

commented Oct 25, 2016

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

@maciej-gurban

This comment has been minimized.

Copy link

commented Nov 28, 2016

@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?

@julianfrank

This comment has been minimized.

Copy link

commented Jan 8, 2017

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...

@cristiangiagante

This comment has been minimized.

Copy link

commented Jan 25, 2019

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

@ivanlmj

This comment has been minimized.

Copy link

commented Apr 25, 2019

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

@mo18

This comment has been minimized.

Copy link

commented May 20, 2019

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
10 participants
You can’t perform that action at this time.