My directory structure:
- clippy/
- docker-compose.yml
- src/
- Dockerfile.local
What I was doing wrong on my docker-compose file
Incorrect
dockerfile: ./../Dockerfile.local
Wrong relative path ./../Dockerfile.local
version: "3.8"
services:
app:
build:
context: ./src
dockerfile: ./../Dockerfile.local
container_name: clippy-app
depends_on:
- postgres
restart: unless-stopped
tty: true
working_dir: /var/www
volumes:
- ./src:/var/www
I just removed the ./ from ./../ and it was working.
Right version of Docker Compose:
version: "3.8"
services:
app:
build:
context: ./src
dockerfile: ../Dockerfile.local
container_name: clippy-app
depends_on:
- postgres
restart: unless-stopped
tty: true
working_dir: /var/www
volumes:
- ./src:/var/www
Any command we write on Dockerfile to create/copy files,folders are relative to the context.
Below I have explain a Analogy on Docker-compose, Dockerfile and Docker context.
Docker Compose (Head Chef):
Docker Compose is like the head chef managing the entire kitchen. It provides instructions on how to cook various dishes, coordinates the cooking process, and specifies which recipes to follow.
In our analogy, Docker Compose is the head chef giving orders and managing the kitchen.
Build Context (Prep Station):
The build context is like a specific area in the kitchen where certain dishes are prepared. It's the designated prep station.
When Docker Compose says, "Go to the prep station and cook this dish," it means operations should happen in the build context.
Dockerfile (Recipe):
Each Dockerfile is like a specific recipe for a dish. It contains step-by-step instructions on how to build a particular image.
In our analogy, a Dockerfile is a recipe for a dish, and you might have different recipes for different images.
Relative Paths (Location of Ingredients in Prep Station):
Relative paths in the Dockerfile are like instructions in the recipe that refer to the location of ingredients within the prep station (build context).
For example, COPY ./spices.txt /dish/ means to copy the spices.txt file from the prep station to a location in the dish being prepared.
Specifying Dockerfile in Docker Compose:
When you specify the Dockerfile in Docker Compose with dockerfile: ../Dockerfile.local, it's like saying, "The recipe for this particular dish is not in the prep station; it's in another recipe book (Dockerfile.local) one level up from the prep station."
In summary, Docker Compose is the head chef, the build context is the designated prep station, each Dockerfile is a recipe, and relative paths in the Dockerfile refer to locations within the prep station. I hope this clarification helps!
Top comments (0)