Introduction
In this lab, you’ll first deploy an application by setting up network, multiple containers individually. Then you will clean up resources, and deploy the same application using Docker Compose.
Task 1: Create a Bridge Network
Create a bridge network named clicknet.
BASH
docker network create --driver bridge clicknetVerify
$ docker network ls
NETWORK ID NAME DRIVER SCOPE
5aa54ade2dcc bridge bridge local
fc40bfcbce91 clicknet bridge local
238b23f4e2a9 host host local
59b9cbf97489 none null localTask 2: Run a Redis Container
Create a background container named redis using the redis:alpine image and attach it to the clicknet network.
BASH
docker run -d \
--name redis \
--network clicknet \
redis:alpineTask 3: Run the Click Counter App
Create a container named clickcounter using the kodekloud/click-counter image, attach it to clicknet, and publish the application’s port (5000) on host port 8085.
BASH
docker run -d \
--name clickcounter \
--network clicknet \
-p 8085:5000 \
kodekloud/click-counterTask 4: Clean Up
Remove the containers and network.
BASH
docker rm -f redis clickcounterBASH
docker network rm clicknetTask 5: Deploy with Docker Compose
Create a compose.yaml file in clickcounter with the following services:
redis- Image:
redis:alpine
- Image:
clickcounter- Image:
kodekloud/click-counter - The application listens on port
5000. - Expose it on host port
8085.
- Image:
Solution
compose.yaml
services:
redis:
image: redis:alpine
clickcounter:
image: kodekloud/click-counter
ports:
- 8085:5000
depends_on:
- redisStart the stack:
BASH
docker compose up -d