Linux Containers
⏱
3 mins remaining
Volumes and Networks
Docker Volumes
Docker volumes provide a way to persist data generated by and used by Docker containers. Volumes are separate from the container file system and can be shared among multiple containers.
docker volume create my_volume
docker run -d -v my_volume:/path/in/container my_image
In the above example:
my_volumeis the name of the volume./path/in/containeris the path inside the container where the volume is mounted.my_imageis the Docker image used to create the container.
Docker Networks:
Docker networks allow communication between containers, enabling services within different containers to interact. Docker provides default bridge networks, and users can create custom networks.
docker network create my_network
docker run -d --network=my_network --name=container1 my_image1
docker run -d --network=my_network --name=container2 my_image2
In the above example:
my_networkis the name of the custom network.container1and container2 are the names of the Docker containers.my_image1and my_image2 are the Docker images used to create the containers.