Reputation: 4413
This is my Dockerfile for an spring boot app
FROM openjdk:8u151-jdk-alpine
VOLUME /tmp
ADD target/classes/application.properties /workdir/application.properties
ADD target/foo-app-2.0.0.jar /workdir/app.jar
WORKDIR /workdir
ENV JAVA_OPTS=""
EXPOSE 8080
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar app.jar" ]
It creates a volume /tmp
when the container is started which is stored in /var/lib/docker
folder of the host.
Is that volume deleted when the container is stopped i.e. everything from the host machine for that volume is cleaned up? If not how do I configure that?
Upvotes: 0
Views: 2838
Reputation: 14863
Adding to @Whites11 answer -
No, volumes are not deleted automatically/by_default (even if the container gets deleted) and you can list them using
docker volume ls
command.
However, once your containers are stopped you can remove the volumes associated with them by using rm -v
:
$ docker stop $CONTAINER_ID && docker rm -v $CONTAINER_ID
Manual -
Usage: docker rm [OPTIONS] CONTAINER [CONTAINER...]
Remove one or more containers
Options:
-f, --force Force the removal of a running container (uses SIGKILL)
-l, --link Remove the specified link
-v, --volumes Remove the volumes associated with the container
Upvotes: 3
Reputation: 13270
No, volumes are not deleted automatically (even if the container gets deleted) and you can list them using the docker volume ls
command.
This could cause the presence of a possibly high number of dangling volumes (volumes not associated to any container) in the host. To remove them you can use this command for example:
docker volume rm `docker volume ls -q -f dangling=true`
(Took from here https://coderwall.com/p/hdsfpq/docker-remove-all-dangling-volumes)
Upvotes: 3