Docker數據管理,即Docker內部以及容器之間管理數據,主要有兩種方式:數據卷和掛載。html
volume,可供一個或多個容器使用的特殊目錄。nginx
docker volume prune
命令刪除無效的volume)數據卷的使用,相似於Linux下對目錄或文件進行mount操做,鏡像中被指定爲掛載點的目錄中的文件會隱藏掉,能顯示看的是掛載的數據卷。docker
docker volume
命令bash
-bash-4.2# docker volume --help Usage: docker volume COMMAND Manage volumes Options: --help Print usage Commands: create Create a volume inspect Display detailed information on one or more volumes ls List volumes prune Remove all unused volumes rm Remove one or more volumes Run 'docker volume COMMAND --help' for more information on a command.
錯誤的掛載code
-bash-4.2# docker run -it --rm -p 1992:80 --name mynginx -v ./:/usr/local/nginx/html mynginx:v1.0.0 docker: Error response from daemon: create ./: "./" includes invalid characters for a local volume name, only "[a-zA-Z0-9][a-zA-Z0-9_.-]" are allowed. If you intented to pass a host directory, use absolute path. See 'docker run --help'.
正確的掛載orm
-bash-4.2# pwd /home/yvhqbat/docker/nginx_docker -bash-4.2# docker run -it --rm -p 1992:80 --name mynginx -v /home/yvhqbat/docker/nginx_docker:/usr/local/nginx/html mynginx:v1.0.0
一個容器的啓動腳本,能夠寫出以下 start.sh:htm
#!/bin/bash docker stop mynginx #docker image rm mynginx:v1.0.0 #docker image load -i mynginx.tar WORKDIR=`pwd` docker run -dit --rm -p 1992:80 --name mynginx -v $WORKDIR:/usr/local/nginx/html mynginx:v1.0.0