Docker Data Volumes
In docker, data volumes are useful for managing your data with Docker containers and host machines. Here you will find two way of managing data volumes on Docker containers.
- Using the data volume container.
- Using share data between the host and the Docker container
#1. Use Docker Data Volume Container
The Docker data volume container is the same as other containers, but they are just used for storage only. You can use storage of these containers in your containers. When you write data to your container's file system, it will be originally written to a storage container.
Create Data Volume Container:
The above command will launch a container with the name “data_container” having data volume at /data. The container will stop immediately due to no service. Now create your application container with –volumes-from flag.
Use Data Volume to New Container:
This will provide you shell access to the newly created container. Now use /data directory to create any number of files and directories on it.
Now you can exit from the current instance. Also, you're remote this using the docker remove command. After that launch a new instance using the same data volume and try to access the files created under /data directory.
Verify Files on Data Volume:
Let’s launch another container with the same data volumes and check available files on /data directory.
#2. Sharing Host Volume to Docker Container
You can also share data between the host machine and the docker container. For example, you can share /var/www directory of the host machine to /data directory. You can share any directory of the host machine to a container.
Here /var/www is a directory on the host machine. Which is mounted on /data directory in Docker container.
0 Comments
CAN FEEDBACK
Emoji