Skip to main content

Day 18 - Advance Docker Concepts

Published 5 min readMarkdown
Day 18 - Advance Docker Concepts

Hello Readers👩‍💻👩‍💻👩‍💻

it's day 18 of #90daysofdevops

Today's topic

✅What are Microservice and Monolithic Services?

✅Docker Network

✅Docker Compose

✅Task for day 18

MicroServices and Monolithic Services

Monolithic architecture refers to an application design where all components or modules of the application are tightly coupled and interconnected. In a monolithic application, the entire software system is developed as a single, indivisible unit. The different functionalities of the application, such as user interface, business logic, and data access, are all bundled together into a single executable or deployable unit.

Microservices Architecture: Microservices architecture is an architectural style where an application is divided into small, loosely coupled, and independent services. Each service represents a specific business capability and can be developed, deployed, and scaled independently of other services. Communication between services is typically achieved through lightweight protocols like HTTP/REST or message queues.

Docker Network

Docker network refers to the networking capabilities provided by Docker, an open-source platform for containerization. Docker allows you to create and manage networks that enable communication between containers running on the same host or across multiple hosts in a distributed environment

  1. Bridge Network: The default network driver used by Docker. It creates an internal private network on the host and assigns a unique IP address to each container connected to the network. Containers within the bridge network can communicate with each other using these IP addresses.

  2. Host Network: When containers are run in the host network mode, they share the network stack with the host. This means that the containers have the same network namespace as the host and can directly access host resources without any port mapping. However, this mode can lead to port conflicts if multiple containers try to bind to the same port.

  3. Overlay Network: Overlay networks enable communication between containers running on different Docker hosts. They use the overlay network driver to encapsulate container traffic in an overlay network, allowing containers to communicate across different hosts in a cluster.

  4. MACVLAN Network: MACVLAN allows containers to have their own MAC and IP addresses on the physical network. This enables containers to appear as separate physical devices on the network and have direct access to network resources.

  5. None Network: The none network driver disables networking for a container. Containers using this driver have no network connectivity, which can be useful in certain scenarios where network access is not required.

Docker Compose

Docker Compose is a tool provided by Docker that simplifies the process of defining and managing multi-container Docker applications. It allows you to define an application's services, networks, and volumes in a declarative YAML file called docker-compose.yml. By using Docker Compose, you can define a group of related services, specify their configurations, and manage their interactions.

YAML

YAML (YAML Ain't Markup Language) is a human-readable data serialization format commonly used for configuration files, data exchange, and structuring data in a concise and easy-to-read manner. It is often used in combination with tools and frameworks like Docker Compose, Kubernetes, Ansible, and others.

YAML files use a .yml or .yaml extension.

Syntax of YAML file

Example of YAML file

Tasks

Tasks 1 - Learn how to use the docker-compose.yml file, to set up the environment, configure the services and links between different containers, and also to use environment variables in the docker-compose.yml file.

First, we install we need to install Docker Compose on our Local I m using Ubuntu Here. I m installing docker-compose on my Ubuntu machine.

First, we need to update the system

We need to install the docker-compose

To check whether the docker-compose is installed or not

Once the docker-compose is installed we can configure docker-compose.yaml file

Let's understand the docker Compose file

version 3.3

The version field specifies the version of the Docker Compose file syntax being used. In this case, it's using version 3.3.

The services section defines the services to be created and their configurations. In this case, there are two services: web and db.

or the web service:

  • The image field specifies the Docker image to use for the web service, which is nginx:latest.

  • The depends_on field indicates that the web service depends on the db service. It ensures that the db service is started before the web service.

  • The ports field maps the host machine's port 80 to the container's port 80. This allows accessing the web service via localhost:80 on the host machine.

    For the db service:

    • The image field specifies the Docker image to use for the db service, which is the default mysql image.

    • The ports field maps the host machine's port 3306 to the container's port 3306. This allows accessing the MySQL service via localhost:3306 on the host machine.

    • The environment field sets the environment variables for the db service. In this case, it sets the MYSQL_ROOT_PASSWORD variable to "test@123", providing a password for the root user in the MySQL database.

Once the services are defined, to start the containers

Task-2

  • Pull a pre-existing Docker image from a public repository (e.g. Docker Hub) and run it on your local machine. Run the container as a non-root user (Hint- Use usermod command to give user permission to docker). Make sure you reboot instance after giving permission to user.

  • Inspect the container's running processes and exposed ports using the docker inspect command.

  • Use the docker logs command to view the container's log output.

  • Use the docker stop and docker start commands to stop and start the container.

  • Use the docker rm command to remove the container when you're done.

I m pulling the nginx image

Run the container as a non-root user

Inspect the container's running processes and exposed ports using the docker inspect command

The docker inspect command is used to retrieve detailed information about Docker objects, such as containers, images, volumes, networks, and more

docker images

docker inspect

Use the docker logs command to view the container's log output.

Use the docker stop and docker start commands to stop and start the container

Use the docker rm command to remove the container when you're done

Check the available the images


I appreciate you taking the time to read my blog, and I hope you found it informative. If you found the content useful, please consider giving it a like, sharing it with others, and following me for more similar posts in the future. Thank you for your support!

LinkedIn Profile-https://www.linkedin.com/in/shreyakhangan/

No comments yet. Be the first to comment.

More from this blog