It would be useful if one could do this
docker-compose build service1 service2 --no-cache
Just realized the syntax is
docker-compose build --no-cache service1 service2
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 :)
+1
Is the --force-recreate needed ?
+1
I think --force-recreate
is the best choice
--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
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!
--no-cache does not work.... what is the alternative --force-rebuild continues to use cache :(
@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
?
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...
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
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
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
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...
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
Most helpful comment
Just realized the syntax is
docker-compose build --no-cache service1 service2