docker volume code example
Example 1: docker mount volume
docker run -v /host/directory:/container/directory -other -options image_name command_to_run
Example 2: docker container
docker container ls -a
docker ps -a
docker container stop [ID]
docker container run -d -p 80:80 --name nginx-server nginx
Example 3: docker create volume
$ docker volume create hello
hello
$ docker run -d -v hello:/world busybox ls /world
Example 4: docker cp volume
Usage
docker cp [OPTIONS] CONTAINER:SRC_PATH DEST_PATH|-
docker cp [OPTIONS] SRC_PATH|- CONTAINER:DEST_PATH
To copy data from the volume to the host, use a temporary container that has the volume mounted.
CID=$(docker run -d -v hello:/hello busybox true)
docker cp $CID:/hello ./
To copy a directory from the host to volume
cd local_dir
docker cp . $CID:/hello/
Then clean up the temporary container.
docker rm $CID
Example 5: docker create volume
docker volume create [OPTIONS] [VOLUME]
Example 6: docker volumes copy content
CID=$(docker run -d -v hello:/hello busybox true)
docker cp $CID:/hello ./