Skip to main content

Command Palette

Search for a command to run...

๐ŸšขDay 19 - Exploring Docker Volume & Docker Network

Published
โ€ข3 min read
๐ŸšขDay 19 - Exploring Docker Volume & Docker Network
P

Hey there! ๐Ÿ‘‹

I'm Pratik R. Mandge, a DevOps Engineer passionate about all things AWS DevOps Technology. Currently on a learning adventure, I'm here to share my journey and Blog's in the world of cloud and DevOps.

๐Ÿ› ๏ธ My focus? Making sense of AWS services, improving CI/CD, and diving into infrastructure as code. Whether you're fellow interns or curious enthusiasts, let's grow together in the vibrant DevOps space.

๐ŸŒ Connect with me for friendly chats, shared experiences, and learning moments. Here's to embracing the learning curve and thriving in the exciting world of AWS DevOps Technology!

Follow me on LinkedIn: https://www.linkedin.com/in/pratik-mandge363

Docker Volume

Docker allows you to create something called volumes. Volumes are stored outside the container's filesystem, which allows them to persist even if the container is stopped or deleted. Volumes are often used to share data between containers or to persist data across container restarts.

You can create a volume using the docker volume create command:

docker volume create myvolume

Docker Network

In simple terms, a Docker network is like a virtual bridge that allows Docker containers to communicate with each other and with the outside world. It provides a way for containers to find and talk to each other, even if they are running on different machines or hosts. Think of it as a private network just for your Docker containers, where they can share data and services.

Task-1: Create a multi-container docker-compose file which will bring UP and bring DOWN containers in a single shot

It's simple example of a multi-container Docker Compose file that includes an application and a database container. This example uses a Python Flask application with a PostgreSQL database.

version: '3.8'

services:
  web:
    image: python:3.9-slim
    volumes:
      - ./app:/app
    working_dir: /app
    command: ["python", "app.py"]
    ports:
      - "5000:5000"
    depends_on:
      - db

  db:
    image: postgres:13
    environment:
      POSTGRES_DB: mydatabase
      POSTGRES_USER: myuser
      POSTGRES_PASSWORD: mypassword
    ports:
      - "5432:5432"

To bring up the containers, run:

docker-compose up -d

To bring down the containers, run:

docker-compose down

This will stop and remove all containers, networks, and volumes associated with the application defined in the docker-compose.yml file.

Task-2: Learn how to use Docker Volumes and Named Volumes to share files and directories between multiple containers.

To demonstrate using Docker Volumes and Named Volumes to share files between multiple containers, we'll create two containers that read and write data to the same volume.

Create a Docker Volume:

docker volume create myvolume

Create a file inside the volume:

echo "Hello, Docker Volumes!" | docker run -i --mount source=myvolume,target=/data alpine sh -c 'cat > /data/file.txt'

Verify that the file exists in the volume:

docker run --rm --mount source=myvolume,target=/data alpine ls /data

Create a second container and verify that it can read the file:

docker run --rm --mount source=myvolume,target=/data alpine cat /data/file.txt

You can use the docker exec command to run commands inside each container and verify that the data is the same in both containers. For example:

docker exec <container_id> cat /data/file.txt #Remember to replace <container_id> with the actual ID or name of the container.

Conclusion

In this task, we learned how to use Docker Volumes and Named Volumes to share files and directories between multiple containers. We created a Docker volume named myvolume, wrote data to a file inside the volume from one container, and then read the same file from another container. This demonstrates how Docker Volumes can be used to share data between containers, allowing them to access and modify the same files.

I'm confident that this blog will prove to be valuable, helping you discover new insights and learn something enriching .๐Ÿ™

๐Ÿ˜ŠHappy Learning : )

T

We use Docker all day. Thanks for sharing Docker basics.

1

More from this blog

๐Ÿš€ ๐——๐—ฎ๐˜† ๐Ÿญ ๐—ผ๐—ณ ๐— ๐˜† ๐Ÿณ-๐——๐—ฎ๐˜† ๐—”๐—ช๐—ฆ ๐—–๐—ต๐—ฎ๐—น๐—น๐—ฒ๐—ป๐—ด๐—ฒ ๐ŸŒŸ

Today, I kicked off my AWS Challenge with a deep dive into several fundamental concepts. Hereโ€™s what I covered: ๐Ÿท๏ธ ๐˜ผ๐™’๐™Ž ๐™‹๐™ง๐™ž๐™˜๐™ž๐™ฃ๐™œ ๐™ˆ๐™ค๐™™๐™š๐™ก๐™จ:AWS offers various pricing models to cater to different business needs: ๐Ÿญ) ๐—ข๐—ป-๐——๐—ฒ๐—บ๐—ฎ๐—ป๐—ฑ ๐—œ๐—ป...

May 22, 20242 min read
๐Ÿš€ ๐——๐—ฎ๐˜† ๐Ÿญ ๐—ผ๐—ณ ๐— ๐˜† ๐Ÿณ-๐——๐—ฎ๐˜† ๐—”๐—ช๐—ฆ ๐—–๐—ต๐—ฎ๐—น๐—น๐—ฒ๐—ป๐—ด๐—ฒ ๐ŸŒŸ

๐ŸŒŸ ๐—˜๐˜…๐—ฝ๐—น๐—ผ๐—ฟ๐—ถ๐—ป๐—ด ๐˜๐—ต๐—ฒ ๐—ž๐—ฒ๐˜† ๐—–๐—ผ๐—บ๐—ฝ๐—ผ๐—ป๐—ฒ๐—ป๐˜๐˜€ ๐—ผ๐—ณ ๐—ž๐˜‚๐—ฏ๐—ฒ๐—ฟ๐—ป๐—ฒ๐˜๐—ฒ๐˜€ ! ๐ŸŒŸ

Kubernetes is designed to automate the deployment, scaling, and operation of application containers. The architecture is divided into two main components: ๐™ˆ๐™–๐™จ๐™ฉ๐™š๐™ง and ๐™’๐™ค๐™ง๐™ ๐™š๐™ง. Hereโ€™s a detailed breakdown: ๐Ÿ”ถ๐™ˆ๐™–๐™จ๐™ฉ๐™š๐™ง ๐™‰๐™ค๐™™๐™š ๐˜พ๐™ค๐™ข๐™ฅ๐™ค๏ฟฝ...

May 19, 20242 min read
๐ŸŒŸ ๐—˜๐˜…๐—ฝ๐—น๐—ผ๐—ฟ๐—ถ๐—ป๐—ด ๐˜๐—ต๐—ฒ ๐—ž๐—ฒ๐˜† ๐—–๐—ผ๐—บ๐—ฝ๐—ผ๐—ป๐—ฒ๐—ป๐˜๐˜€ ๐—ผ๐—ณ ๐—ž๐˜‚๐—ฏ๐—ฒ๐—ฟ๐—ป๐—ฒ๐˜๐—ฒ๐˜€ ! ๐ŸŒŸ

โ›…๏ธImportant AWS Services: Part - 3

๐Ÿš€๐™€๐™ญ๐™˜๐™ž๐™ฉ๐™š๐™™ ๐™ฉ๐™ค ๐™จ๐™๐™–๐™ง๐™š ๐™ข๐™ฎ ๐™š๐™ญ๐™ฅ๐™š๐™ง๐™ฉ๐™ž๐™จ๐™š ๐™ž๐™ฃ ๐˜ผ๐™’๐™Ž ๐™ฌ๐™ž๐™ฉ๐™ ๐™– ๐™›๐™ค๐™˜๐™ช๐™จ ๐™ค๐™ฃ ๐™˜๐™ค๐™ฃ๐™ฉ๐™–๐™ž๐™ฃ๐™š๐™ง๐™ž๐™ฏ๐™–๐™ฉ๐™ž๐™ค๐™ฃ ๐™–๐™ฃ๐™™ ๐™™๐™š๐™ฅ๐™ก๐™ค๐™ฎ โ–ถ๏ธ๐—”๐—บ๐—ฎ๐˜‡๐—ผ๐—ป ๐—˜๐—น๐—ฎ๐˜€๐˜๐—ถ๐—ฐ ๐—ž๐˜‚๐—ฏ๐—ฒ๐—ฟ๐—ป๐—ฒ๐˜๐—ฒ๐˜€ ๐—ฆ๐—ฒ๐—ฟ๐˜ƒ๐—ถ๐—ฐ๐—ฒ (๐—˜๐—ž๐—ฆ): โ–ช๏ธFully managed Kuberne...

May 12, 20242 min read
โ›…๏ธImportant AWS Services: Part - 3

โ›…๏ธImportant AWS Services: Part - 2

โšœ๏ธ๐™„๐™ข๐™ฅ๐™ค๐™ง๐™ฉ๐™–๐™ฃ๐™ฉ ๐™ฌ๐™ž๐™™๐™š ๐™ง๐™–๐™ฃ๐™œ๐™š ๐™ค๐™› ๐˜ผ๐™’๐™Ž ๐™จ๐™š๐™ง๐™ซ๐™ž๐™˜๐™š๐™จ ๐™ฉ๐™๐™–๐™ฉ ๐™˜๐™–๐™ฃ ๐™š๐™ฃ๐™–๐™—๐™ก๐™š ๐™ฉ๐™ค ๐™–๐™ง๐™˜๐™๐™ž๐™ฉ๐™š๐™˜๐™ฉ ๐™จ๐™˜๐™–๐™ก๐™–๐™—๐™ก๐™š, ๐™จ๐™š๐™˜๐™ช๐™ง๐™š, ๐™–๐™ฃ๐™™ ๐™š๐™›๐™›๐™ž๐™˜๐™ž๐™š๐™ฃ๐™ฉ ๐™˜๐™ก๐™ค๐™ช๐™™ ๐™จ๐™ค๐™ก๐™ช๐™ฉ๐™ž๐™ค๐™ฃ๐™จ. ๐™ƒ๐™š๐™ง๐™š ๐™–๐™ง๐™š ๐™จ๐™ค๐™ข๐™š ๐™ ๐™š๐™ฎ ๐™จ๐™š๐™ง...

May 10, 20243 min read
โ›…๏ธImportant AWS Services: Part - 2

PratikM's Blog

49 posts