July 12, 2019

Part 3: Docker Interview Questions And Answers (docker-compose command)

How to use the docker-compose command?
Docker Compose is used to run multiple containers as a single service.

This command is used to power multi-container applications where various services will be hosted inside different containers.


With docker-compose command you can: Build images, scale containers, heal containers, view output from containers, list the public port of a container, and much more.

1). Install Docker Compose
Even if you've installed Docker on your server, chances are Docker Compose wasn't installed along with it. In order to install Docker Compose, issue the following commands:

sudo curl -L "https://github.com/docker/compose/releases/download/1.23.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

Next, we need to provide execute privileges to the downloaded Docker Compose file, using the following command:
sudo chmod +x /usr/local/bin/docker-compose

Verify the installation with the command:
docker-compose version

2). Creating Docker-Compose File
We need to create Docker Compose file first. All Docker Compose files are YAML files. We can create one using the vim editor by executing following command:

sudo vim docker-compose.yml



Now let’s run our Docker Compose file using the following command:
sudo ./docker-compose up 

The above command will take the docker-compose.yml file in your local directory and start building the containers. Once executed, all the images will start downloading and the containers will start automatically.

We can use 'docker ps' to verify whether the containers are indeed up and running.

-K Himaanshu Shuklaa..

No comments:

Post a Comment