Day 18:Docker for DevOps Engineers

Day 18:Docker for DevOps Engineers

Docker Compose

Docker Compose is used to run multiple containers as a single service. For example, suppose you had an application that required NGNIX and MySQL, you could create one file which would start both containers as a service without the need to start each one separately.

It is a tool that is used to create and start Docker applications by using a single command. We can use it to file to configure our application's services.

In this chapter, we will see how to get started with Docker Compose. Then, we will look at how to get a simple service with MySQL and NGNIX up and running using Docker Compose.

What is YAML?

  • YAML is a data serialization language that is often used for writing configuration files. Depending on whom you ask, YAML stands for yet another markup language or YAML ain’t markup language (a recursive acronym), which emphasizes that YAML is for data, not documents.

  • YAML is a popular programming language because it is human-readable and easy to understand.

  • YAML files use a .yml or .yaml extension.

    Task-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.

  • Update the package manager and install docker on your machine.

Install Docker-compose.

Create a docker-compose.yaml file.

-3.3 is the version of the docker-compose.

-services contain the number of containers or applications the user wants to run.

-Ports refer to the particular application being exposed to an external URL.

-Environment passes the credentials to be passed to the container.

Step 4:Run docker-compose.yml file using docker-compose up -d

Step 5: Check containers using the command docker ps

Step 6: Check whether your application is running or not.

Step 7: To stop the service- docker-compose down

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 the user permission to docker). Make sure you reboot the instance after permitting the user.

Step 1: Pull the docker image from the docker hub.

Step 2: Run the container using the command docker run -d –name <name> -p <port number>

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.

To stop the container use the command docker stop <container name>

To start the container use the command docker start <container name>

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

Thank you for reading!!!!