Map host-local directory into container
docker run --volume $(pwd):/src alpine
Silently creates source if it does not exist
docker run --mount type=bind,source=$(pwd),target=/src alpine
Throws error if source does not exist
–
docker run -it --rm \
--volume $(pwd):/src \
alpine
Local directory will be created silently:
docker run -it --rm \
--volume $(pwd)/missing:/src \
alpine
–
docker run -it --rm \
--mount type=bind,source=$(pwd),target=/src \
alpine
Fails of local directory does not exist:
docker run -it --rm \
--mount type=bind,source=$(pwd)/missing,target=/src \
alpine
–
docker volume create myvol
docker volume ls
docker volume inspect myvol
docker -it --rm --volume myvol:/src alpine
Bind mounts are useful for development:
docker run \
--mount type=bind,source=$(pwd),target=/src \
--workdir /src \
maven
But this creates root-owned files
Fix file permissions:
docker run \
--mount type=bind,source=$(pwd),target=/src \
--workdir /src \
--user $(id -u):$(id -g) \
maven
–
docker -it --rm --volume myvol:/src:ro alpine
Works for bind mounts as well
docker run -it --rm --tmpfs /src alpine
–
docker-compose
XXX https://docs.docker.com/compose/compose-file/#long-syntax-3
–
VOLUME
XXX creates new volume
XXX volume is not cleaned
XXX docker container rm –volumes
XXX docker run –rm removes those volumes
–
XXX