Day 19 Task: Docker for DevOps Engineers
Published: 2024-06-29 15:51:41

**What is Docker Volume..?**
Docker-Volume is a feature in the Docker containerization platform that enables data to persist between containers and to be shared among them. When you create a Docker container, any data that is generated or used by the container is stored inside the container itself. However, when the container is deleted, the data is also deleted.

To solve this problem, Docker-Volume was introduced. It allows you to store the data in a separate location outside the container, making it independent of the container’s lifecycle. This way, even if the container is deleted, the data remains accessible and can be used by other containers as well.

Docker-Volume can be used to manage the storage requirements of your containers. It enables you to easily manage the data for your applications, such as databases, log files, and other persistent data. Docker-Volume can also be used to store configuration files, templates, and other files that are required by the container.

Overall, Docker-Volume is a powerful feature that allows for flexible and scalable data management in Docker containers.



**Why Volumes over Bind Mount?**
Volumes have several advantages over bind mounts:

Volumes are easier to back up or migrate than bind mounts.

You can manage volumes using Docker CLI commands or the Docker API.

Volumes work on both Linux and Windows containers.

Volumes can be more safely shared among multiple containers.

Volume drivers let you store volumes on remote hosts or cloud providers, encrypt the contents of volumes, or add other functionality.

New volumes can have their content pre-populated by a container.

Volumes on Docker Desktop have much higher performance than bind mounts from Mac and Windows hosts.

Unlike a bind mount, you can create and manage volumes outside the scope of any container.

Volumes on the Docker host


**Commands related to Docker Volumes**

**Create a volume:**

```
docker volume create my-vol
```
**List volumes:**

```
docker volume ls
```

**Inspect a volume:**

```
docker volume inspect my-vol
```
**Remove a volume:**

```
docker volume rm my-vol
```
**Attach a Volume to a Container:**

```
docker run -v myvolume:/path/in/container myimage
```
**Detach a Volume from a Container:**

To detach a volume from a running container, you need to stop and remove the container. The volume will still exist and can be attached to other containers if needed.

```
docker container stop imagename
docker container rm imagename
```
**What is Docker Network..?**

Docker network is a feature in the Docker containerization platform that enables the communication between containers running on the same host or across multiple hosts. It provides a virtual network that connects containers to each other and to external networks, allowing them to communicate securely and efficiently.

When you create a Docker container, it is isolated from the host system and other containers by default. To enable communication between containers, you can create a Docker network and attach containers to it. Once the containers are attached to the same network, they can communicate with each other by their container names or IP addresses.

Docker network provides several types of network drivers, including Bridge, Host, Overlay, Macvlan, and none. The bridge is the default network driver and allows containers to communicate with each other on the same host. Host allows containers to use the host network stack, while Overlay enables the communication between containers on different hosts. Macvlan allows containers to have a unique MAC address and appear as physical devices on the network, while none disables networking for the container.

Docker network also supports network segmentation and isolation, allowing you to create multiple networks and assign containers to specific networks based on their function or security requirements. This helps to improve the security and performance of your Docker environment.

Overall, the Docker network is a powerful feature that enables communication between containers and provides flexible and secure networking options for your Docker environment.

**Commands related to Docker Network**

**Create a Network:**

```
docker network create mynetwork
```
**List Networks:**

```
docker network ls
```
**Inspect a Network:**

```
docker network inspect mynetwork
```
**Connect a Container to a Network:**

```
docker run --network mynetwork myimage
```

**Disconnect a Container from a Network:**

```
docker network disconnect mynetwork mycontainer
```
**Remove a Network:**

```
docker network rm mynetwork
```
Thank you for reading!! Hope you find this helpful.

#day19challenge#90daysofdevops