#90DAYSOFDEVOPSCHALLENGE
Day 18 — Docker for DevOps Engineers.
• Docker Compose :
Docker Compose is a tool that was developed to help define and share multi-container applications. With Compose, we can create a YAML file to define the services and with a single command, can spin everything up or tear it all down.
The big advantage of using Compose is you can define your application stack in a file, keep it at the root of your project repo (it’s now version controlled), and easily enable someone else to contribute to your project. Someone would only need to clone your repo and start the compose app. In fact, you might see quite a few projects on GitHub/GitLab doing exactly this now. Docker Compose can also be used to scale a service, update images, and view the logs of the running containers.
Docker Compose simplifies the process of managing multi-container applications by allowing developers to define all of the services that make up an application in a single file, and then start and stop all of the services with a single command. It also allows for easy scaling and updating the services, and view logs.
• What is YAML..?
YAML is a data serialization language. Back when it came out in 2001, YAML stood for “Yet Another Markup Language.” The acronym was later changed to “YAML Ain’t Markup Language” to emphasize that the language is intended for data and not documents.
It is not a programming language in the true sense of the word. YAML files store information, so they do not include actions and decisions.
Unlike XML or JSON, YAML presents data in a way that makes it easy for a human to read. The simple syntax does not impact the language’s capabilities. Any data or structure added to an XML or JSON file can also be stored in YAML.
Besides human-readable code, YAML also features:
- Cross-language data portability
- A consistent data model
- One-pass processing
- Ease of implementation and use
TASK-1 :
- Learn how to use the docker-compose.yaml file, to set up the environment, configure the services and links between different containers, and also to use environment variables in the docker-compose.yaml file.
Step 1 : Update your package manager and install docker in your.
sudo apt-get install docker
Step 2 : Install Docker-compose.
sudo apt-get install docker-compose
Step 3 : Create a “docker-compose.yml” file inside project folder.
Step 4 : Now to build and run your app with Compose use command.
sudo apt-get install docker compose
sudo apt-get install docker compose up -d
Step 5 : Once containers as up we can check it’s details with “ sudo docker ps”.
Step 6 : To check locally, Our Nginx-server container is running at port 808.
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.
To pull an existing Docker image from Docker Hub and run it on your local machine, you can use the “docker pull” command followed by the image name.
sudo docker pull nginx:latest
- Inspect the container’s running processes and exposed ports using the docker inspect command.
To inspect the container’s running processes and exposed ports using the “docker inspect” command, you can use the following command:
sudo docker inspect container_name
sudo docker inspect nginx
- Use the docker logs command to view the container’s log output.
To view the container’s log output, you can use the “docker logs” command followed by the container id.
sudo docker logs container_id
- Use the docker stop and docker start commands to stop and start the container. Then use the docker rm command to remove the container when you’re done.
To stop the container, you can use the “sudo docker stop container_id”
sudo docker stop container_id
To remove the container when you’re done, you can use the “sudo docker rm” command followed by the container_id.
sudo docker rm container_id