Skip to contentমূল লেখায় যান

Topic 07 · DevOps & Cloudটপিক 07 · DevOps & Cloud

Docker Images and Compose

This page explains how a test environment is built and started: how a Dockerfile builds an image, why the order of its instructions matters, and how Docker Compose starts an application and the services that it needs from one file, with a practice run of Docker's own Compose Quickstart. It builds on Docker Basics; Docker in Practice goes deeper into volumes and networks.

13 min read13 মিনিটে পড়া যায় · 7 sections7টি সেকশন · 18 sources18টি সোর্স · updated Nov 2026আপডেট: Nov 2026

Why one edit rebuilds so muchএকটা এডিটে এত রিবিল্ড কেন

Edit one file and see which Dockerfile layers are rebuilt and which come from the build cache.একটা ফাইল বদলান আর দেখুন Dockerfile-এর কোন লেয়ারগুলো আবার তৈরি হয়, কোনগুলো বিল্ড ক্যাশ থেকে আসে।

2 min2 মিনিট7 steps7টি ধাপ
  • Layers rebuiltআবার তৈরি লেয়ার4 / 4
  • Cache hitsক্যাশে পাওয়া0 / 4
  • Build timeবিল্ডের সময়94 s
Order: source firstক্রম: সোর্স আগেran · 4 sচলেছে · 4 sFROM python:3.12-alpineFROM python:3.12-alpineran · 2 sচলেছে · 2 sCOPY . .COPY . .ran · 88 sচলেছে · 88 sRUN pip installRUN pip installran · 0 sচলেছে · 0 sCMD flask runCMD flask runBuild timeবিল্ডের সময়94 s

You’ll learnআপনি শিখবেন

  • A cached layer costs no timeক্যাশের লেয়ারে সময় লাগে না
  • A changed layer affects every layer after itবদলানো লেয়ার তার পরের সব লেয়ারকে প্রভাবিত করে
  • Why the package files are copied firstকেন package ফাইল আগে কপি হয়
  • A multi-stage build keeps only the final stageমাল্টি-স্টেজ বিল্ড শুধু ফাইনাল স্টেজ রাখে

What it is

Dockerfile. A Dockerfile is a text document that contains all the commands a user could call on the command line to assemble an image Source 1সোর্স 1. Docker runs instructions in a Dockerfile in order Source 1সোর্স 1. A Dockerfile must begin with a FROM instruction Source 1সোর্স 1.

docker build. docker build is an alias of docker buildx build, which starts a build using BuildKit Source 2সোর্স 2. Its -t (--tag) option sets the image identifier, in the format [registry/]repository[:tag] Source 2সোর্স 2.

Docker Compose. Docker Compose is a tool for defining and running multi-container applications Source 9সোর্স 9. It manages services, networks, and volumes in a single YAML configuration file Source 9সোর্স 9. With a single command, you create and start all the services from your configuration file Source 9সোর্স 9. The default path for a Compose file is compose.yaml (preferred) or compose.yml in the working directory Source 10সোর্স 10. Compose works in all environments: production, staging, development, testing, as well as CI workflows Source 9সোর্স 9.

Bake. Bake is a feature of Docker Buildx that lets you define your build configuration using a declarative file, as opposed to specifying a complex CLI expression Source 18সোর্স 18. It also lets you run multiple builds concurrently with a single invocation Source 18সোর্স 18. A Bake file can be written in HCL or JSON format, and Bake can also build directly from a Docker Compose file Source 18সোর্স 18.

ToolReadsCommand
Docker buildA Dockerfile Source 1সোর্স 1docker build Source 2সোর্স 2
Docker ComposeA compose.yaml Source 10সোর্স 10docker compose up Source 11সোর্স 11
BakeA Bake file in HCL or JSON, or a Compose file Source 18সোর্স 18docker buildx bake Source 18সোর্স 18

সহজ English

Dockerfile. A Dockerfile is a text file. It holds all the commands that a user could run on the command line to make an image Source 1সোর্স 1. Docker runs the instructions of a Dockerfile in order Source 1সোর্স 1. A Dockerfile must start with a FROM instruction Source 1সোর্স 1.

docker build. docker build is another name for docker buildx build, which starts a build with BuildKit Source 2সোর্স 2. Its -t (--tag) option gives the image its name, in the form [registry/]repository[:tag] Source 2সোর্স 2.

Docker Compose. Docker Compose is a tool for defining and running applications that have more than one container Source 9সোর্স 9. It manages services, networks, and volumes in one YAML file Source 9সোর্স 9. With one command, you create and start all the services of that file Source 9সোর্স 9. By default, the Compose file is compose.yaml (preferred) or compose.yml, in the folder that you work in Source 10সোর্স 10. Compose works in all environments: production, staging, development, testing, and CI workflows Source 9সোর্স 9.

Bake. Bake is a feature of Docker Buildx. You write your build settings in a declarative file, instead of a complex command line Source 18সোর্স 18. It can also run many builds at the same time with one command Source 18সোর্স 18. A Bake file can be in HCL or JSON, and Bake can also build straight from a Docker Compose file Source 18সোর্স 18.

ToolReadsCommand
Docker buildA Dockerfile Source 1সোর্স 1docker build Source 2সোর্স 2
Docker ComposeA compose.yaml Source 10সোর্স 10docker compose up Source 11সোর্স 11
BakeA Bake file in HCL or JSON, or a Compose file Source 18সোর্স 18docker buildx bake Source 18সোর্স 18

বাংলা ব্যাখ্যা

Dockerfile। Dockerfile হলো একটা text document, যাতে image assemble করার জন্য একজন user command line-এ যত command চালাতে পারে, সব থাকে Source 1সোর্স 1। Docker একটা Dockerfile-এর instruction-গুলো ক্রম অনুযায়ী চালায় Source 1সোর্স 1। একটা Dockerfile অবশ্যই FROM instruction দিয়ে শুরু হতে হবে Source 1সোর্স 1।

docker build। docker build হলো docker buildx build-এর আরেক নাম (alias), যা BuildKit দিয়ে একটা build শুরু করে Source 2সোর্স 2। এর -t (--tag) option image-এর identifier ঠিক করে, [registry/]repository[:tag] format-এ Source 2সোর্স 2।

Docker Compose। Docker Compose হলো একাধিক container-এর application define আর run করার একটা tool Source 9সোর্স 9। এটা একটা YAML configuration file-এ service, network আর volume পরিচালনা করে Source 9সোর্স 9। একটা command দিয়েই আপনি configuration file-এর সব service তৈরি করে চালু করেন Source 9সোর্স 9। Compose file-এর default path হলো working directory-তে রাখা compose.yaml (পছন্দনীয়) বা compose.yml Source 10সোর্স 10। Compose সব environment-এ কাজ করে: production, staging, development, testing, আর CI workflow-তেও Source 9সোর্স 9।

Bake। Bake হলো Docker Buildx-এর একটা feature, যা দিয়ে জটিল CLI expression না লিখে একটা declarative file-এ build configuration define করা যায় Source 18সোর্স 18। এটা একবারের invocation-এ একাধিক build একসাথে চালাতেও দেয় Source 18সোর্স 18। Bake file HCL বা JSON format-এ লেখা যায়, আর Bake সরাসরি একটা Docker Compose file থেকেও build করতে পারে Source 18সোর্স 18।

Toolকী পড়েCommand
Docker buildএকটা Dockerfile Source 1সোর্স 1docker build Source 2সোর্স 2
Docker Composeএকটা compose.yaml Source 10সোর্স 10docker compose up Source 11সোর্স 11
BakeHCL বা JSON-এ একটা Bake file, বা একটা Compose file Source 18সোর্স 18docker buildx bake Source 18সোর্স 18

How it works

The instructions of a Dockerfile. These are the instructions of the Dockerfile in the practice run below:

InstructionWhat it does
FROMSpecifies the base image from which you are building Source 1সোর্স 1
WORKDIRSets the working directory for any RUN, CMD, ENTRYPOINT, COPY and ADD instructions that follow it Source 1সোর্স 1
ENVSets the environment variable <key> to the value <value> Source 1সোর্স 1
RUNExecutes any commands to create a new layer on top of the current image Source 1সোর্স 1
COPYCopies new files or directories from <src> and adds them to the filesystem of the image at the path <dest> Source 1সোর্স 1
EXPOSEDoesn't actually publish the port. It is documentation about which ports are intended to be published Source 1সোর্স 1
CMDProvides defaults for an executing container. If you list more than one CMD, only the last one takes effect Source 1সোর্স 1

The build context. The build context is the set of files that your build can access Source 3সোর্স 3. Docker sends everything in your project directory to the daemon when it builds an image Source 11সোর্স 11. A .dockerignore file is a newline-separated list of patterns similar to the file globs of Unix shells Source 3সোর্স 3. It keeps unneeded files out of the build context Source 11সোর্স 11.

The build cache. If a layer changes, all other layers that come after it are also affected Source 4সোর্স 4. So make expensive steps appear near the beginning of the Dockerfile, and steps that change often near the end Source 5সোর্স 5. Docker's own example: copy the package management files first, then install the dependencies, and only then copy the project source code, which is subject to frequent change Source 5সোর্স 5.

Multi-stage builds. With multi-stage builds, you use multiple FROM statements in your Dockerfile Source 6সোর্স 6. You can selectively copy artifacts from one stage to another, leaving behind everything you don't want in the final image Source 6সোর্স 6.

How Compose starts services. By default, Compose sets up a single network for your app Source 14সোর্স 14. Each container for a service joins that network, and it is reachable by other containers on it and discoverable by its service name Source 14সোর্স 14. Compose always starts and stops containers in dependency order Source 13সোর্স 13. But on startup, Compose does not wait until a container is "ready", only until it's running Source 13সোর্স 13. To wait for a dependency, use the condition attribute: with service_healthy, the dependency must be "healthy", as defined with healthcheck, before the dependent service starts Source 13সোর্স 13.

This diagram is the tutorial's own picture of the practice run below:

compose.yaml ── docker compose up ──> network: compose-demo_default
                                         │
                 redis (image: redis:alpine)   healthcheck: redis-cli ping
                    ▲  becomes healthy
                    │  depends_on: condition: service_healthy
                 web (build: .)   port 8000 on the host ──> 5000 in the container
                 redis keeps its data in the named volume redis-data

সহজ English

The instructions of a Dockerfile. These are the instructions of the Dockerfile in the practice run below:

InstructionWhat it does
FROMNames the base image that you build on Source 1সোর্স 1
WORKDIRSets the working folder for the RUN, CMD, ENTRYPOINT, COPY and ADD instructions after it Source 1সোর্স 1
ENVSets an environment variable to a value Source 1সোর্স 1
RUNRuns commands, and makes a new layer on top of the image so far Source 1সোর্স 1
COPYCopies files or folders from <src> into the image at the path <dest> Source 1সোর্স 1
EXPOSEDoes not really publish the port. It only notes which ports are meant to be published Source 1সোর্স 1
CMDGives the default for a running container. If there is more than one CMD, only the last one counts Source 1সোর্স 1

The build context. The build context is the set of files that your build can use Source 3সোর্স 3. When Docker builds an image, it sends everything in your project folder to the daemon Source 11সোর্স 11. A .dockerignore file is a list of patterns, one per line, like the file patterns of Unix shells Source 3সোর্স 3. It keeps files that the build does not need out of the build context Source 11সোর্স 11.

The build cache. If a layer changes, all the layers after it are affected too Source 4সোর্স 4. So put expensive steps near the top of the Dockerfile, and steps that change often near the end Source 5সোর্স 5. Docker's own example: first copy the files that list the packages, then install the packages, and only then copy the source code, which changes often Source 5সোর্স 5.

Multi-stage builds. In a multi-stage build, the Dockerfile has more than one FROM Source 6সোর্স 6. You can pick which files to copy from one stage to the next, and leave the rest out of the final image Source 6সোর্স 6.

How Compose starts services. By default, Compose makes one network for your app Source 14সোর্স 14. Each service container joins it. Other containers on it can reach the container, and find it by its service name Source 14সোর্স 14. Compose always starts and stops containers in the order of their dependencies Source 13সোর্স 13. But when it starts them, it waits only until a container is running, not until it is "ready" Source 13সোর্স 13. To wait for a dependency, use condition: with service_healthy, the dependency must be "healthy" first, as its healthcheck defines Source 13সোর্স 13.

This diagram is the tutorial's own picture of the practice run below:

compose.yaml ── docker compose up ──> network: compose-demo_default
                                         │
                 redis (image: redis:alpine)   healthcheck: redis-cli ping
                    ▲  becomes healthy
                    │  depends_on: condition: service_healthy
                 web (build: .)   port 8000 on the host ──> 5000 in the container
                 redis keeps its data in the named volume redis-data

বাংলা ব্যাখ্যা

Dockerfile-এর instruction। নিচের practice run-এর Dockerfile-এ এই instruction-গুলো আছে:

Instructionকী করে
FROMকোন base image থেকে build করছেন, তা নির্দিষ্ট করে Source 1সোর্স 1
WORKDIRপরের সব RUN, CMD, ENTRYPOINT, COPY আর ADD instruction-এর working directory ঠিক করে Source 1সোর্স 1
ENVenvironment variable <key>-এর মান <value> করে Source 1সোর্স 1
RUNযেকোনো command চালায়, আর বর্তমান image-এর ওপরে একটা নতুন layer তৈরি করে Source 1সোর্স 1
COPY<src> থেকে নতুন file বা directory copy করে image-এর filesystem-এ <dest> path-এ যোগ করে Source 1সোর্স 1
EXPOSEআসলে port publish করে না। কোন port publish করার কথা, এটা তার একটা documentation Source 1সোর্স 1
CMDচলমান container-এর default দেয়। একাধিক CMD থাকলে শুধু শেষটা কার্যকর হয় Source 1সোর্স 1

Build context। build context হলো file-এর সেই set, যেগুলো আপনার build পড়তে পারে Source 3সোর্স 3। image build করার সময় Docker আপনার project directory-র সবকিছু daemon-এর কাছে পাঠায় Source 11সোর্স 11। .dockerignore file হলো Unix shell-এর file glob-এর মতো pattern-এর একটা তালিকা, প্রতি লাইনে একটা Source 3সোর্স 3। এটা অদরকারি file build context-এর বাইরে রাখে Source 11সোর্স 11।

Build cache। একটা layer বদলালে তার পরের সব layer-ও প্রভাবিত হয় Source 4সোর্স 4। তাই ব্যয়বহুল ধাপ Dockerfile-এর শুরুর দিকে রাখুন, আর ঘনঘন বদলায় এমন ধাপ শেষের দিকে Source 5সোর্স 5। Docker-এর নিজের উদাহরণ: আগে package management file copy করুন, তারপর dependency install করুন, আর একদম শেষে project-এর source code copy করুন, যেটা ঘনঘন বদলায় Source 5সোর্স 5।

Multi-stage build। multi-stage build-এ Dockerfile-এ একাধিক FROM statement থাকে Source 6সোর্স 6। এক stage থেকে আরেক stage-এ বেছে বেছে artifact copy করা যায়, আর final image-এ যা চান না তা পেছনে রেখে আসা যায় Source 6সোর্স 6।

Compose কীভাবে service চালু করে। default-ভাবে Compose আপনার app-এর জন্য একটা network তৈরি করে Source 14সোর্স 14। প্রতিটা service-এর container সেই network-এ যুক্ত হয়, আর সেখানকার অন্য container তাকে পৌঁছাতে পারে, আর service-এর নাম দিয়ে খুঁজে পায় Source 14সোর্স 14। Compose সবসময় dependency-র ক্রম অনুযায়ী container চালু ও বন্ধ করে Source 13সোর্স 13। কিন্তু চালু করার সময় Compose একটা container "ready" হওয়া পর্যন্ত অপেক্ষা করে না, শুধু running হওয়া পর্যন্ত করে Source 13সোর্স 13। কোনো dependency-র জন্য অপেক্ষা করতে condition attribute ব্যবহার করুন: service_healthy দিলে dependent service চালুর আগে dependency-কে "healthy" হতে হয়, যেটা healthcheck দিয়ে define করা Source 13সোর্স 13।

এই diagram নিচের practice run-এর টিউটোরিয়ালের নিজের ছবি:

compose.yaml ── docker compose up ──> network: compose-demo_default
                                         │
                 redis (image: redis:alpine)   healthcheck: redis-cli ping
                    ▲  becomes healthy
                    │  depends_on: condition: service_healthy
                 web (build: .)   port 8000 on the host ──> 5000 in the container
                 redis keeps its data in the named volume redis-data

Try it

This practice run is Docker's Compose Quickstart: a small Flask web app that counts visits in Redis Source 11সোর্স 11. It needs Docker Compose Source 11সোর্স 11. The tutorial ran it on 2026-11-16 with Docker Engine 29.9.3 and Docker Compose v5.5.1 on Linux. It leaves out the Quickstart's Compose Watch step and its step on multiple Compose files.

1. Make the project. Create a folder and the app Source 11সোর্স 11:

mkdir compose-demo
cd compose-demo

app.py reads its Redis connection details from environment variables, with defaults Source 11সোর্স 11:

import os
import redis
from flask import Flask

app = Flask(__name__)
cache = redis.Redis(
    host=os.getenv("REDIS_HOST", "redis"),
    port=int(os.getenv("REDIS_PORT", "6379")),
)

@app.route("/")
def hello():
    count = cache.incr("hits")
    return f"Hello from Docker! I have been seen {count} time(s).\n"

requirements.txt lists the two Python packages Source 11সোর্স 11:

flask
redis

2. Write the Dockerfile. This is the Quickstart's Dockerfile, without its comments Source 11সোর্স 11. Name the file Dockerfile with no extension: some editors add .txt automatically, which causes the build to fail Source 11সোর্স 11.

# syntax=docker/dockerfile:1
FROM python:3.12-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["flask", "run", "--debug"]

Note the order: requirements.txt is copied and installed before the rest of the code is copied.

3. Keep settings and secrets apart. A .env file holds configuration values, and Compose reads it automatically for interpolation in your compose.yaml Source 11সোর্স 11. The .dockerignore keeps the .env file, which may contain secrets, and cached Python bytecode out of the build context Source 11সোর্স 11:

# .env
APP_PORT=8000
REDIS_HOST=redis
REDIS_PORT=6379
# .dockerignore
.env
*.pyc
__pycache__
redis-data

4. Write compose.yaml. This is the Quickstart's file with its health check and its named volume, without the develop.watch block Source 11সোর্স 11:

services:
  web:
    build: .
    ports:
      - "${APP_PORT}:5000"
    environment:
      - REDIS_HOST=${REDIS_HOST}
      - REDIS_PORT=${REDIS_PORT}
    depends_on:
      redis:
        condition: service_healthy
  redis:
    image: redis:alpine
    volumes:
      - redis-data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 5
      start_period: 10s

volumes:
  redis-data:

The web service uses an image built from the Dockerfile in the current directory, and maps port 8000 on the host to port 5000 in the container Source 11সোর্স 11. The redis service uses a public Redis image from Docker Hub Source 11সোর্স 11. redis-cli ping expects a PONG response; with interval: 5s and retries: 5, the Quickstart says Compose waits up to 25 seconds before giving up Source 11সোর্স 11. The same file also sets a 10-second start_period and a 3-second timeout for each check, so the real wait can be longer. The redis-data:/data entry mounts the named volume at /data, the path where Redis writes its data files Source 11সোর্স 11.

5. Check what Compose will apply. docker compose config works purely from your files, and the variables of .env are replaced with their values Source 11সোর্স 11:

docker compose config

6. Start it. -d runs the containers in the background Source 15সোর্স 15:

docker compose up -d

In the tutorial's run, web started only after redis was healthy:

 Container compose-demo-redis-1 Started
 Container compose-demo-redis-1 Waiting
 Container compose-demo-redis-1 Healthy
 Container compose-demo-web-1 Starting
 Container compose-demo-web-1 Started

Open http://localhost:8000 and refresh: the counter increments on each visit Source 11সোর্স 11. The tutorial's run gave Hello from Docker! I have been seen 1 time(s)., then 2, then 3.

7. Look inside. docker compose logs -f follows the log stream; pass a service name to follow one service Source 11সোর্স 11. docker compose exec runs a command inside an already-running container without starting a new one Source 11সোর্স 11:

docker compose logs -f web
docker compose exec web env | grep REDIS
docker compose exec redis redis-cli GET hits

Press Ctrl+C to stop following the logs; the containers keep running Source 11সোর্স 11. In the tutorial's run, env showed REDIS_HOST=redis and REDIS_PORT=6379, and GET hits returned 3.

8. Stop it, start it again, and reset it. The named volume persists between compose down and compose up cycles Source 11সোর্স 11. --wait waits for services to be running or healthy, and streams their logs unless --detach is set Source 15সোর্স 15:

docker compose down
docker compose up -d --wait

The counter continues from where it left off Source 11সোর্স 11. In the tutorial's run, the next visit gave I have been seen 4 time(s).

This deletes data

docker compose down -v removes named volumes along with the containers: it permanently deletes the stored data Source 11সোর্স 11.

docker compose down -v

সহজ English

This practice run is Docker's Compose Quickstart: a small Flask web app that counts visits in Redis Source 11সোর্স 11. You need Docker Compose Source 11সোর্স 11. The tutorial ran it on 2026-11-16 with Docker Engine 29.9.3 and Docker Compose v5.5.1 on Linux. It leaves out the Quickstart's Compose Watch step and its step on more than one Compose file.

1. Make the project. Create a folder and the app Source 11সোর্স 11:

mkdir compose-demo
cd compose-demo

app.py gets the Redis address from environment variables, and has defaults Source 11সোর্স 11:

import os
import redis
from flask import Flask

app = Flask(__name__)
cache = redis.Redis(
    host=os.getenv("REDIS_HOST", "redis"),
    port=int(os.getenv("REDIS_PORT", "6379")),
)

@app.route("/")
def hello():
    count = cache.incr("hits")
    return f"Hello from Docker! I have been seen {count} time(s).\n"

requirements.txt lists the two Python packages Source 11সোর্স 11:

flask
redis

2. Write the Dockerfile. This is the Quickstart's Dockerfile, without its comments Source 11সোর্স 11. Name the file Dockerfile, with no extension: some editors add .txt by themselves, and then the build fails Source 11সোর্স 11.

# syntax=docker/dockerfile:1
FROM python:3.12-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["flask", "run", "--debug"]

Note the order: requirements.txt is copied and installed before the rest of the code is copied.

3. Keep settings and secrets apart. A .env file holds settings, and Compose reads it by itself to fill in the values in your compose.yaml Source 11সোর্স 11. The .dockerignore keeps the .env file, which may hold secrets, and cached Python bytecode out of the build context Source 11সোর্স 11:

# .env
APP_PORT=8000
REDIS_HOST=redis
REDIS_PORT=6379
# .dockerignore
.env
*.pyc
__pycache__
redis-data

4. Write compose.yaml. This is the Quickstart's file with its health check and its named volume, without the develop.watch block Source 11সোর্স 11:

services:
  web:
    build: .
    ports:
      - "${APP_PORT}:5000"
    environment:
      - REDIS_HOST=${REDIS_HOST}
      - REDIS_PORT=${REDIS_PORT}
    depends_on:
      redis:
        condition: service_healthy
  redis:
    image: redis:alpine
    volumes:
      - redis-data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 5
      start_period: 10s

volumes:
  redis-data:

The web service uses an image built from the Dockerfile in this folder, and connects port 8000 on the host to port 5000 in the container Source 11সোর্স 11. The redis service uses a public Redis image from Docker Hub Source 11সোর্স 11. redis-cli ping expects the answer PONG; with interval: 5s and retries: 5, the Quickstart says Compose waits up to 25 seconds before it gives up Source 11সোর্স 11. The same file also sets a 10-second start_period and a 3-second timeout for each check, so the real wait can be longer. redis-data:/data mounts the named volume at /data, where Redis writes its data files Source 11সোর্স 11.

5. Check what Compose will apply. docker compose config works only from your files, and puts in the values of .env Source 11সোর্স 11:

docker compose config

6. Start it. -d runs the containers in the background Source 15সোর্স 15:

docker compose up -d

In the tutorial's run, web started only after redis was healthy:

 Container compose-demo-redis-1 Started
 Container compose-demo-redis-1 Waiting
 Container compose-demo-redis-1 Healthy
 Container compose-demo-web-1 Starting
 Container compose-demo-web-1 Started

Open http://localhost:8000 and refresh: the counter goes up on each visit Source 11সোর্স 11. The tutorial's run gave Hello from Docker! I have been seen 1 time(s)., then 2, then 3.

7. Look inside. docker compose logs -f follows the logs; add a service name to follow only that service Source 11সোর্স 11. docker compose exec runs a command in a container that is already running, without starting a new one Source 11সোর্স 11:

docker compose logs -f web
docker compose exec web env | grep REDIS
docker compose exec redis redis-cli GET hits

Press Ctrl+C to stop following the logs; the containers keep running Source 11সোর্স 11. In the tutorial's run, env showed REDIS_HOST=redis and REDIS_PORT=6379, and GET hits returned 3.

8. Stop it, start it again, and reset it. The named volume stays between compose down and compose up Source 11সোর্স 11. --wait waits until the services are running or healthy, and shows their logs unless you also use -d Source 15সোর্স 15:

docker compose down
docker compose up -d --wait

The counter goes on from where it stopped Source 11সোর্স 11. In the tutorial's run, the next visit gave I have been seen 4 time(s).

This deletes data

docker compose down -v removes the named volumes with the containers: it deletes the stored data for good Source 11সোর্স 11.

docker compose down -v

বাংলা ব্যাখ্যা

এই practice run হলো Docker-এর Compose Quickstart: একটা ছোট Flask web app, যা Redis-এ visit গোনে Source 11সোর্স 11। এর জন্য Docker Compose লাগে Source 11সোর্স 11। টিউটোরিয়াল এটা 2026-11-16 তারিখে Linux-এ Docker Engine 29.9.3 আর Docker Compose v5.5.1 দিয়ে চালিয়েছে। এখানে Quickstart-এর Compose Watch ধাপ আর একাধিক Compose file-এর ধাপ বাদ দেওয়া হয়েছে।

১. project তৈরি করুন। একটা folder আর app তৈরি করুন Source 11সোর্স 11:

mkdir compose-demo
cd compose-demo

app.py Redis connection-এর তথ্য environment variable থেকে পড়ে, default মানসহ Source 11সোর্স 11:

import os
import redis
from flask import Flask

app = Flask(__name__)
cache = redis.Redis(
    host=os.getenv("REDIS_HOST", "redis"),
    port=int(os.getenv("REDIS_PORT", "6379")),
)

@app.route("/")
def hello():
    count = cache.incr("hits")
    return f"Hello from Docker! I have been seen {count} time(s).\n"

requirements.txt-এ দুটো Python package-এর নাম থাকে Source 11সোর্স 11:

flask
redis

২. Dockerfile লিখুন। এটা Quickstart-এর Dockerfile, comment ছাড়া Source 11সোর্স 11। file-এর নাম কোনো extension ছাড়া Dockerfile রাখুন: কিছু editor নিজে থেকে .txt যোগ করে, তাতে build ফেল করে Source 11সোর্স 11।

# syntax=docker/dockerfile:1
FROM python:3.12-alpine
WORKDIR /code
ENV FLASK_APP=app.py
ENV FLASK_RUN_HOST=0.0.0.0
RUN apk add --no-cache gcc musl-dev linux-headers
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 5000
CMD ["flask", "run", "--debug"]

ক্রমটা খেয়াল করুন: বাকি code copy করার আগে requirements.txt copy করে install করা হয়।

৩. setting আর secret আলাদা রাখুন। একটা .env file configuration-এর মান রাখে, আর Compose নিজে থেকেই সেটা পড়ে আপনার compose.yaml-এ interpolation-এর জন্য দেয় Source 11সোর্স 11। .dockerignore .env file (যাতে secret থাকতে পারে) আর cache করা Python bytecode build context-এর বাইরে রাখে Source 11সোর্স 11:

# .env
APP_PORT=8000
REDIS_HOST=redis
REDIS_PORT=6379
# .dockerignore
.env
*.pyc
__pycache__
redis-data

৪. compose.yaml লিখুন। এটা Quickstart-এর file, health check আর named volume-সহ, develop.watch block ছাড়া Source 11সোর্স 11:

services:
  web:
    build: .
    ports:
      - "${APP_PORT}:5000"
    environment:
      - REDIS_HOST=${REDIS_HOST}
      - REDIS_PORT=${REDIS_PORT}
    depends_on:
      redis:
        condition: service_healthy
  redis:
    image: redis:alpine
    volumes:
      - redis-data:/data
    healthcheck:
      test: ["CMD", "redis-cli", "ping"]
      interval: 5s
      timeout: 3s
      retries: 5
      start_period: 10s

volumes:
  redis-data:

web service বর্তমান directory-র Dockerfile থেকে build করা image ব্যবহার করে, আর host-এর port 8000-কে container-এর port 5000-এর সাথে map করে Source 11সোর্স 11। redis service Docker Hub-এর একটা public Redis image ব্যবহার করে Source 11সোর্স 11। redis-cli ping একটা PONG উত্তর আশা করে; interval: 5s আর retries: 5 থাকলে Quickstart বলে হাল ছাড়ার আগে Compose সর্বোচ্চ 25 সেকেন্ড অপেক্ষা করে Source 11সোর্স 11। একই ফাইলে 10 সেকেন্ডের start_period আর প্রতি check-এর জন্য 3 সেকেন্ডের timeout-ও আছে, তাই আসল অপেক্ষা আরও বেশি হতে পারে। redis-data:/data named volume-টা /data-তে mount করে, যেখানে Redis তার data file লেখে Source 11সোর্স 11।

৫. Compose কী প্রয়োগ করবে, দেখে নিন। docker compose config শুধু আপনার file থেকে কাজ করে, আর .env-এর variable-গুলোর জায়গায় তাদের মান বসায় Source 11সোর্স 11:

docker compose config

৬. চালু করুন। -d container-গুলো background-এ চালায় Source 15সোর্স 15:

docker compose up -d

টিউটোরিয়ালের run-এ redis healthy হওয়ার পরেই web চালু হয়েছে:

 Container compose-demo-redis-1 Started
 Container compose-demo-redis-1 Waiting
 Container compose-demo-redis-1 Healthy
 Container compose-demo-web-1 Starting
 Container compose-demo-web-1 Started

http://localhost:8000 খুলে refresh করুন: প্রতিবার visit-এ counter বাড়ে Source 11সোর্স 11। টিউটোরিয়ালের run-এ এসেছে Hello from Docker! I have been seen 1 time(s)., তারপর 2, তারপর 3।

৭. ভেতরে দেখুন। docker compose logs -f log-এর ধারা অনুসরণ করে; একটা service-এর নাম দিলে শুধু সেটারই log দেখায় Source 11সোর্স 11। docker compose exec নতুন container চালু না করে আগে থেকে চলা একটা container-এর ভেতরে command চালায় Source 11সোর্স 11:

docker compose logs -f web
docker compose exec web env | grep REDIS
docker compose exec redis redis-cli GET hits

log অনুসরণ থামাতে Ctrl+C চাপুন; container চলতেই থাকে Source 11সোর্স 11। টিউটোরিয়ালের run-এ env দেখিয়েছে REDIS_HOST=redis আর REDIS_PORT=6379, আর GET hits দিয়েছে 3।

৮. থামান, আবার চালু করুন, তারপর reset করুন। named volume compose down আর compose up-এর মাঝেও টিকে থাকে Source 11সোর্স 11। --wait service-গুলো running বা healthy হওয়া পর্যন্ত অপেক্ষা করে; --detach না দিলে সেগুলোর log দেখায় Source 15সোর্স 15:

docker compose down
docker compose up -d --wait

counter যেখানে থেমেছিল, সেখান থেকে চলতে থাকে Source 11সোর্স 11। টিউটোরিয়ালের run-এ পরের visit দিয়েছে I have been seen 4 time(s).

This deletes data

docker compose down -v container-এর সাথে named volume-ও মুছে দেয়: জমা data স্থায়ীভাবে মুছে যায় Source 11সোর্স 11।

docker compose down -v

How a tester uses it

One file for the whole test environment. Compose manages services, networks, and volumes in a single YAML configuration file Source 9সোর্স 9. With a custom project name, the same compose.yaml file can be deployed twice on the same infrastructure, without changes Source 10সোর্স 10. You can set the project name with the --project-name flag or the COMPOSE_PROJECT_NAME environment variable Source 14সোর্স 14.

Start the tests only when the services are ready. docker compose up --wait waits for services to be running or healthy Source 15সোর্স 15. --wait-timeout sets the maximum duration in seconds to wait Source 15সোর্স 15. Healthy needs a healthcheck on the service Source 13সোর্স 13.

Use a test container's exit code. --exit-code-from returns the exit code of the selected service container Source 15সোর্স 15. It implies --abort-on-container-exit, which stops all containers if any container was stopped Source 15সোর্স 15. If the up process itself encounters an error, its exit code is 1 Source 15সোর্স 15.

Reset data between runs. By default, docker compose down removes only the containers for services, the networks defined in the Compose file, and the default network Source 16সোর্স 16. -v (--volumes) also removes named volumes declared in the volumes section and anonymous volumes attached to containers Source 16সোর্স 16.

Find out what was really running. docker compose config shows the fully resolved configuration Source 11সোর্স 11. docker compose logs views output from containers, and -t shows timestamps Source 17সোর্স 17. docker compose exec is the primary tool for live debugging Source 11সোর্স 11.

Build a fresh image to test. The --pull flag forces Docker to check for and download a newer version of the base image Source 8সোর্স 8. The --no-cache flag disables the build cache, forcing Docker to rebuild all layers from scratch Source 8সোর্স 8. Docker's example uses both Source 8সোর্স 8:

docker build --pull --no-cache -t my-image:my-tag .

Builds and tests in Bake. The Bake documentation lists workflows such as running tests and lint checks, and exporting build artifacts Source 18সোর্স 18.

সহজ English

One file for the whole test environment. Compose manages services, networks, and volumes in one YAML file Source 9সোর্স 9. With its own project name, the same compose.yaml can run twice on the same infrastructure, with no changes Source 10সোর্স 10. You can set the project name with the --project-name flag or the COMPOSE_PROJECT_NAME environment variable Source 14সোর্স 14.

Start the tests only when the services are ready. docker compose up --wait waits until the services are running or healthy Source 15সোর্স 15. --wait-timeout sets the longest wait, in seconds Source 15সোর্স 15. To be healthy, a service needs a healthcheck Source 13সোর্স 13.

Use a test container's exit code. --exit-code-from returns the exit code of the service container that you name Source 15সোর্স 15. It also turns on --abort-on-container-exit, which stops all containers when any container stops Source 15সোর্স 15. If up itself hits an error, it exits with code 1 Source 15সোর্স 15.

Reset data between runs. By default, docker compose down removes only the service containers, the networks of the Compose file, and the default network Source 16সোর্স 16. -v (--volumes) also removes the named volumes of the volumes section and the anonymous volumes of the containers Source 16সোর্স 16.

Find out what was really running. docker compose config shows the full, final configuration Source 11সোর্স 11. docker compose logs shows the output of the containers, and -t adds timestamps Source 17সোর্স 17. docker compose exec is the main tool for debugging while the stack runs Source 11সোর্স 11.

Build a fresh image to test. --pull makes Docker check for a newer base image and download it Source 8সোর্স 8. --no-cache turns off the build cache, so Docker builds all layers again Source 8সোর্স 8. Docker's example uses both Source 8সোর্স 8:

docker build --pull --no-cache -t my-image:my-tag .

Builds and tests in Bake. The Bake documentation lists workflows such as running tests and lint checks, and exporting build artifacts Source 18সোর্স 18.

বাংলা ব্যাখ্যা

পুরো test environment একটা file-এ। Compose একটা YAML configuration file-এ service, network আর volume পরিচালনা করে Source 9সোর্স 9। আলাদা একটা project name দিলে একই compose.yaml file কোনো পরিবর্তন ছাড়াই একই infrastructure-এ দুবার deploy করা যায় Source 10সোর্স 10। project name --project-name flag বা COMPOSE_PROJECT_NAME environment variable দিয়ে ঠিক করা যায় Source 14সোর্স 14।

service ready হলে তবেই test শুরু করুন। docker compose up --wait service-গুলো running বা healthy হওয়া পর্যন্ত অপেক্ষা করে Source 15সোর্স 15। --wait-timeout সর্বোচ্চ কত সেকেন্ড অপেক্ষা করবে, তা ঠিক করে Source 15সোর্স 15। healthy হতে service-এ একটা healthcheck লাগে Source 13সোর্স 13।

test container-এর exit code কাজে লাগান। --exit-code-from বেছে নেওয়া service container-এর exit code ফেরত দেয় Source 15সোর্স 15। এটা --abort-on-container-exit-ও বোঝায়, যেটা কোনো container থেমে গেলে সব container থামিয়ে দেয় Source 15সোর্স 15। up process নিজে কোনো error-এ পড়লে তার exit code হয় 1 Source 15সোর্স 15।

দুই run-এর মাঝে data reset করুন। default-ভাবে docker compose down শুধু service-এর container, Compose file-এ define করা network আর default network মোছে Source 16সোর্স 16। -v (--volumes) volumes section-এ ঘোষণা করা named volume আর container-এর সাথে যুক্ত anonymous volume-ও মুছে দেয় Source 16সোর্স 16।

আসলে কী চলছিল, জানুন। docker compose config পুরোপুরি resolve করা configuration দেখায় Source 11সোর্স 11। docker compose logs container-এর output দেখায়, আর -t timestamp দেখায় Source 17সোর্স 17। চলন্ত অবস্থায় debugging-এর প্রধান tool হলো docker compose exec Source 11সোর্স 11।

test করার জন্য একটা নতুন image build করুন। --pull flag Docker-কে base image-এর নতুন version খুঁজে download করতে বাধ্য করে Source 8সোর্স 8। --no-cache flag build cache বন্ধ করে, ফলে Docker সব layer শুরু থেকে আবার build করে Source 8সোর্স 8। Docker-এর উদাহরণে দুটোই আছে Source 8সোর্স 8:

docker build --pull --no-cache -t my-image:my-tag .

Bake-এ build আর test। Bake-এর documentation-এ test আর lint check চালানো, আর build artifact export করার মতো workflow-এর তালিকা আছে Source 18সোর্স 18।

Common mistakes

সহজ English

বাংলা ব্যাখ্যা

  • শুধু depends_on-এর ওপর ভরসা করা। short syntax-এ Compose dependent service চালুর আগে dependency service-গুলো "healthy" হওয়ার জন্য অপেক্ষা করে না Source 12সোর্স 12। একটা application তার database-এর আগে চালু হলে SQL statement সামলাতে পারে এমন database খুঁজে না-ও পেতে পারে Source 13সোর্স 13। একটা healthcheck আর condition: service_healthy যোগ করুন Source 13সোর্স 13।
  • quote ছাড়া port। YAML-এর base-60 float-এর সাথে গোলমাল এড়াতে HOST:CONTAINER সবসময় quote করা string হিসেবে লিখুন Source 12সোর্স 12।
  • সবার জন্য খোলা port। host IP (যেমন 127.0.0.1) না দিলে Docker সব interface-এ (0.0.0.0) bind করে, host-এর firewall rule এড়িয়ে Source 12সোর্স 12। host IP-সহ short syntax-এর একটা উদাহরণ হলো "127.0.0.1:8001:8001" Source 12সোর্স 12।
  • build argument বা ENV-এ secret। build-এ secret পাঠানোর জন্য build argument আর environment variable উপযুক্ত নয়, কারণ এগুলো final image-এ থেকে যায় Source 7সোর্স 7।
  • dependency install-এর আগে সব source copy করা। তাহলে যেকোনো file বদলালেই প্রতিটা build-এ সব dependency আবার install হয় Source 5সোর্স 5।
  • docker compose down data মুছে দেবে ভাবা। -v না দিলে named volume থেকে যায় Source 16সোর্স 16। default-ভাবে anonymous volume-ও মোছে না Source 16সোর্স 16।
  • FROM-এর tag-এ ভরসা করা। image tag বদলানো যায়: একজন publisher একটা tag-কে নতুন image-এর দিকে সরিয়ে দিতে পারে Source 8সোর্স 8। digest-এ pin করলে নিশ্চিতভাবে সবসময় একই image version পাওয়া যায় Source 8সোর্স 8।

What a tester can check

Tutorial advice

This list is the tutorial's own advice for a tester on a team that uses Dockerfiles and Compose.

  • Ask for a healthcheck on each service that the tests depend on, and for condition: service_healthy in depends_on.
  • In CI, start the stack with docker compose up --wait before the tests run.
  • Give each parallel test environment its own project name.
  • Ask that base images in FROM are pinned, and record the digest of the image under test.
  • Check that .dockerignore keeps .env files and other secrets out of the build context.
  • Use docker compose down -v only when you mean to delete the test data.
  • Attach the output of docker compose config to a bug report about the environment.

সহজ English

Tutorial advice

This list is the tutorial's own advice for a tester on a team that uses Dockerfiles and Compose.

  • Ask for a healthcheck on each service that the tests depend on, and for condition: service_healthy in depends_on.
  • In CI, start the stack with docker compose up --wait before the tests run.
  • Give each test environment that runs at the same time its own project name.
  • Ask that base images in FROM are pinned, and write down the digest of the image under test.
  • Check that .dockerignore keeps .env files and other secrets out of the build context.
  • Use docker compose down -v only when you really want to delete the test data.
  • Add the output of docker compose config to a bug report about the environment.

বাংলা ব্যাখ্যা

Tutorial advice

এই তালিকা টিউটোরিয়ালের নিজের পরামর্শ, Dockerfile আর Compose ব্যবহার করা টিমের একজন tester-এর জন্য।

  • test যেসব service-এর ওপর নির্ভর করে, সেগুলোর প্রতিটায় একটা healthcheck, আর depends_on-এ condition: service_healthy চান।
  • CI-তে test চালানোর আগে docker compose up --wait দিয়ে stack চালু করুন।
  • একসাথে চলা প্রতিটা test environment-কে আলাদা project name দিন।
  • FROM-এর base image যেন pin করা হয়, তা চান, আর test করা image-এর digest লিখে রাখুন।
  • দেখুন .dockerignore .env file আর অন্য secret build context-এর বাইরে রাখে কি না।
  • test data সত্যিই মুছতে চাইলে তবেই docker compose down -v ব্যবহার করুন।
  • environment নিয়ে bug report-এ docker compose config-এর output যোগ করুন।

Key words

TermMeaning
DockerfileA text document with all the commands a user could call on the command line to assemble an image
docker buildAn alias of docker buildx build, which starts a build using BuildKit
Build contextThe set of files that your build can access
.dockerignoreA newline-separated list of patterns that keeps files out of the build context
Build cacheIf a layer changes, all other layers that come after it are also affected, so the order of the instructions matters
Multi-stage buildA Dockerfile with multiple FROM statements that copies only the artifacts it needs into the final image
Docker ComposeA tool for defining and running multi-container applications
compose.yamlThe default Compose file in the working directory
ServiceAn entry under services in compose.yaml, such as web or redis; its containers are discoverable by the service name
healthcheckHow Compose tests whether a service is healthy, such as redis-cli ping
condition: service_healthyStarts a dependent service only after the dependency is healthy
Project nameThe name that lets the same compose.yaml run twice on the same infrastructure
Named volumeStorage that keeps data between compose down and compose up
BakeA feature of Docker Buildx that defines builds in a declarative file

Reels on this topicএই টপিকের রিলস

Short videos from other creators, picked for this topic. They are not part of this page's fact-checked text. Nothing loads from YouTube until you press Play.অন্য ক্রিয়েটরদের বানানো ছোট ভিডিও, এই টপিকের জন্য বাছাই করা। এগুলো এই পেজের ফ্যাক্ট-চেক করা লেখার অংশ নয়। চালান বাটন চাপার আগে YouTube থেকে কিছুই লোড হয় না।

Show 10 more reelsআরও 10টি রিল দেখান
  1. [1]
    Dockerfile reference

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  2. [2]
    docker buildx build

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  3. [3]
    Build context

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  4. [4]
    Docker build cache

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  5. [5]
    Optimize cache usage in builds

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  6. [6]
    Multi-stage builds

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  7. [7]
    Build secrets

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  8. [8]
    Building best practices

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  9. [9]
    Docker Compose

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  10. [10]
    How Compose works

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  11. [11]
    Docker Compose Quickstart

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  12. [12]
    Workload specification

    Docker Docs · accessed 2026-11-27দেখা হয়েছে: 2026-11-27

  13. [13]
    Control startup and shutdown order in Compose

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  14. [14]
    Networking in Compose

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  15. [15]
    docker compose up

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  16. [16]
    docker compose down

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  17. [17]
    docker compose logs

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16

  18. [18]
    Bake

    Docker Docs · accessed 2026-11-16দেখা হয়েছে: 2026-11-16