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.
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.
How to run Docker commands without sudo?
Make sure docker is installed and system is updated (This is already been completed as a part of previous tasks):
$ sudo usermod -a -G docker $USER
TASK-1:
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.
- Install Docker compose on the system.
$ apt install docker-compose
2 .Pull the source code from the GitHub repo and create the image.
Pull the source code from the GitHub repo and create the image.
$ docker build . -t django-notes-app
3 .Create the docker-compose.yml file and include the containers you want to run with its images.
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 or data to be passed to the container.
4 .Run the docker-compose.yml file.
$ sudo docker-compose up
5 .Now the containers are up and you can monitor the application through the web URL.
6 .After the task completion, you can use the below command to make the docker containers down.
$ sudo 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
docker pull image docker run -d image
Inspect the container's running processes and exposed ports using the docker inspect command.
$ docker inspect <image_name>
Use the docker logs command to view the container's log output.
$ docker logs <container_id>
Use the docker stop and docker start commands to stop and start the container.
$ docker stop <container_id> $ docker start <container_id>
Use the docker rm command to remove the container when you're done.
$ docker rm <container_id>
Thanks for reading my article.✌️✌️