Today I have covered Docker-Compose where I have explained how to connect MongoDB and Mongo-Express using a YAML file.
Till now you have created a Docker-Compose file and pushed it to the Repository. Let's move forward and dig more into other Docker concepts.
What is Docker Compose?
Docker Compose is a tool that allows you to define and run multi-container Docker applications.
It is a tool for defining and running multi-container Docker applications, using a
YAML
file to configure the application's *services
,networks
, andvolumes
.With Docker Compose, you can easily configure and run multiple containers as a single application, making it easier to manage and deploy complex applications.
Docker Compose is often used for developing and testing applications locally, as it allows you to define and
run an entire application stack on a single machine
.It also makes it easy to share your
application's configuration
with other developers, as the configuration is stored in asingle YAML file
that can be committed to version control.
What is YAML?
YAML is a
data serialization
language that is often used for writing configuration files. Depending on whom you ask,YAML
stands forYet 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.
Steps to create Docker-Compose.yaml file :
Step 1:
Version (Version of Docker Compose).
Step 2:
Services (Where we add containers)
Eg.(Containers
,images
,port
,environments
)
Step 3:
We can create multiple environments like this.
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.
Task-2:
Pull a pre-existing Docker image from a public repository (e.g. Docker Hub) and run it on your local machine.
Inspect the container's running processes and exposed ports using the docker inspect command.
docker inspect <container_id>or<image_id>
Use the docker logs command to view the container's log output.
docker log <container_id>
Use the docker stop and docker start commands to stop and start the container.
To stop the docker container
docker stop <container_id>or<image_id>
To start the docker container
docker start <container_id>or<image_id>
Use the docker rm command to remove the container when you're done.
docker rm <container_id>or<image_id>