绑定挂载
- 使用–mount 将当前目录下的target目录,挂载到容器的/app目录下
docker run -d \ -it \ --name devtest \ --mount type=bind,source="$(pwd)"/target,target=/app \ nginx:latest
- 使用 -v 将当前目录下的target目录,挂载到容器的/app目录下
docker run -d \ -it \ --name devtest \ -v "$(pwd)"/target:/app \ nginx:latest
- 只读模式挂载 --mount
docker run -d \ -it \ --name devtest \ --mount type=bind,source="$(pwd)"/target,target=/app,readonly \ nginx:latest
- 只读模式挂载 -v
docker run -d \ -it \ --name devtest \ -v "$(pwd)"/target:/app:ro \ nginx:latest
- 查看挂载详情(查看Mounts部分)
docker inspect devtest
- 删除刚才的容器
docker container stop devtest docker container rm devtest
tmpfs
- 启动容器时挂载(使用–mount)
docker run -d \ -it \ --name tmptest \ --mount type=tmpfs,destination=/app \ nginx:latest
- 使用 --tmpfs
docker run -d \ -it \ --name tmptest \ --tmpfs /app \ nginx:latest
- 查看挂载详情
docker inspect tmptest --format ''
- 挂载时指定参数
docker run -d \ -it \ --name tmptest \ --mount type=tmpfs,destination=/app,tmpfs-mode=1770,tmpfs-size=16k \ nginx:latest