🗼Docker Compose:
Docker Compose is another best tool for docker to setup multi-container environments. Using this create a single compose file with defining all the containers with there environments. You can easily use single command to build images and run all the containers.
There is the three-step process to work with Docker Compose.
1. Define application environment with Dockerfile for all services.
2. Create a docker-compose.yml file defining with all services under application.
3. Run docker-compose up to run all services under applications.🗼Install Docker Compose
Visit the Docker compose official Github page and download the latest version of Docker compose tool. You can also install Docker compose 1.16.1 using the following command. Before installing the specific version, You must check the compatibility on releases page with your docker version.
How to install docker-compose using these command
1.sudo apt-get update
2.sudo apt install docker-compose
Docker Compose Example File
What is YAML?
1.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.
2.YAML is a popular programming language because it is human-readable and easy to understand.
3.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.
🗼Write a yml file whose extension is .yml and write requiremnt statement in the file.
Command used for docker-compose file
# docker-compose up
# docker ps
#docker ps -a
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.#git clone git url
#docker build -t image name .
#docker run -d -p image name
Inspect the container's running processes and exposed ports using the docker inspect command.
#docker inspect container id
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.
Thank you for reading my blog. Don't forget to follow, comment and like my blog...