Answer a question

I got a docker-compose file in which I want to set a context and docker file to look something like this:

build:
  context: <path to context>
  dockerfile: <path to dockerfile>

For now my file is in the root folder so its simply:

build: 
  context: .
  dockerfile: .

This way it does work.

The structure of the project is something like this:

./
  - folder1/
    - folder2/
         docker-compose.yaml
         DockerFile

I want to copy files as part of the commands in the DockerFile and I want the paths to be relative to the root folder of the project.

How with this project structure do I set the context to be the root folder of the project? I tried doing context: ../../ but I then got an error:

Error response from daemon: unexpected error reading Dockerfile: read (path): is a directory

How do I set the context correctly?

Answers

You cannot change the context to be a parent folder, you can read it about it in the docker-compose documentation. https://docs.docker.com/compose/compose-file/compose-file-v3/#context

what you can do is have the composefile in the folder which in the the highest hierarchy and change the context accordingly. like so:

version: "3.7"

services:

  srv2:
    build:
      dockerfile: src/services/srv2/Dockerfile
      context: ./
    image: srv2

  srv1:
    build:
      dockerfile: src/services/srv1/Dockerfile
      context: ./
    
    image: srv1

or you can make the context the directory of the service that contains the Dockerfile of the service

Logo

云原生社区为您提供最前沿的新闻资讯和知识内容

更多推荐