Day 18 Task: 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.
To learn more about docker-compose visit here
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.
Compose is a tool for defining and running multi-container Docker applications. With Compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.
Setting Up the Environment Before we start defining our services, we need to set up our environment. Create a new directory for your project and navigate to it in your terminal. Then, create a new file called docker-compose.yml in this directory.
Configuring Services We will define our services. Each service is defined as a separate block in the docker-compose.yml file. Here is an example of how to define a service:
docker-compose.yml
- Configuring links
docker-compose.yml
- environment variables
docker-compose.yml
Task-2
Pull a pre-existing Docker image from a public repository (e.g. Docker Hub) and run it on your local machine and run the container.
- 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.
How to run Docker commands without sudo?
Make sure docker is installed and the system is updated (This is already been completed as a part of previous tasks):
$ docker --version
$ sudo usermod -a -G docker $USER
$ sudo reboot
Day18 task is completed!
90DaysOfDevOps Tasks👇