Tuesday, March 7, 2023

Docker Compose Installation

 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.


Download docker-compose:

1.Run this command to download the current stable release of Docker Compose:

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

2.Apply executable permissions to the binary:

chmod +x /usr/local/bin/docker-compose

3. #ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

[root@ip-172-31-34-29 DockerDemo]# docker-compose --version

docker-compose version 1.29.2, build 5becea4c


To run a nginx container the manual is

root@ip-172-31-34-29:~$ docker container run -itd nginx 

but if the same container if we want to create using docker-compose file then we need to create a YAML file using vi docker-compose.yaml and snippet is shown below

version: '3'

services:

  nginxwebapp:

    image: nginx

    ports: 

      - "8000:80"

Version :- Property is defined by the specification for backward compatibility but is only informative.

Services:- It defines the number of applications or containers which need to be created. As shown in the above example under nginxwebapp it defines the first container which will get created using image nginx  and expose ports “8000:80”. By giving the image name as nginx, we are specifying the container should get built on nginx and we can give any image name as per the requirement. Ports property defines the port mapping of the host to the container, port 8000 is the host port that will map to port 80 of the container.


[root@ip-172-31-34-29 DockerDemo]# docker-compose up -d

Starting dockerdemo_webapp2_1 ... done

Starting dockerdemo_webapp1_1 ... done

[root@ip-172-31-34-29 DockerDemo]# docker ps

CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS         PORTS                                   NAMES

80ea921350ed   nginx     "/docker-entrypoint.…"   50 seconds ago   Up 2 seconds   0.0.0.0:8001->80/tcp, :::8001->80/tcp   dockerdemo_webapp2_1

d679f04c516f   nginx     "/docker-entrypoint.…"   50 seconds ago   Up 2 seconds   0.0.0.0:8000->80/tcp, :::8000->80/tcp   dockerdemo_webapp1_1


[root@ip-172-31-34-29 DockerDemo]# docker-compose down

Stopping dockerdemo_webapp2_1 ... done

Stopping dockerdemo_webapp1_1 ... done

Removing dockerdemo_webapp2_1 ... done

Removing dockerdemo_webapp1_1 ... done

Removing network dockerdemo_default


Docker Swarm V/s Docker Compose:

The difference between Docker Swarm and Docker Compose is that Compose is used for configuring multiple containers in the same host. Docker Swarm is different in that it is a container orchestration tool. This means that Docker Swarm lets you connect containers to multiple hosts similar to Kubernetes





No comments:

Post a Comment

Sample Game App Deployment on EKS cluster

 https://padmakshi.medium.com/setting-up-an-eks-cluster-and-deploying-a-game-application-a-step-by-step-guide-08790e0be117