How Docker-compose works? |
What is Docker-compose? why?
If we are working on multi-container apps then it is a hassle because we would be doing repeatedly the following tasks:- Build images from Dockerfiles
- Pull images from the Hub or a private registry
- Configure and create multiple containers for each service required to run the application
- Start and stop containers individually each one
- Stream their logs to check the status and troubleshoot
In contrast to all the above hassles, The Docker compose developed as best tool for defining & running multi-container docker applications. We can use YAML files to configure application services (docker-compose.yml) Simplified control for multi-container applications - we can start all services with a single command: docker compose up and can stop all services with a single command: docker compose down
Docker-compose can be used to scale up selected services when required
Features of docker-compose
- We can define and run multi-containerized Docker applications where it could be database, web server, proxy containers to run the complete application.
- Docker-compose uses single YAML file to configure all applications dependent services
- The docker-compose is powerful with a single command, we can create and start all the services from the configuration.
- Mainly for dev and test environments can be used for repetitive tasks which deals with Docker containers
- We can build multiple isolated environments on a single host
- It preserves volume data when containers are created using docker-compose.yaml file.
- Docker-compose has a wonderful feature that, Only recreate containers that have changes
- We could define the variables and moving a composition between environments such as development to test or staging.
Installing Docker-compose
There are two ways to install the docker-compose :
- Using GitHub
- Using pip install
Using GitHub download
Step 1: Run the following curl command to download from the GitHub the current stable release of Docker-composeOld compose worked! But it don't support all compose versions.
sudo curl -L https://github.com/docker/compose/releases/download/1.3.2/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-composeBetter option to use latest version always! take the stable version from the GitHub
sudo curl -L https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-composeStep 2: Apply executable permissions to the docker-compose binary:
ls -l /usr/local/bin/docker-compose #You must be in root user chmod +x /usr/local/bin/docker-compose ls -l /usr/local/bin/docker-compose #Ensure the docker-compose file have execute permissionsStep 3: set the ENV var with the latest path in the bashrc or .bashprofile
echo "export PATH=$PATH:/usr/local/bin" >> .bashrcStep 4: Check the version of docker-compose command
docker-compose -v
Install docker-compose using GitHub download |
No comments:
Post a Comment