Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to copy files in dockerfile without root build context #93

Open
himat opened this issue Mar 23, 2021 · 4 comments
Open

How to copy files in dockerfile without root build context #93

himat opened this issue Mar 23, 2021 · 4 comments
Labels

Comments

@himat
Copy link

himat commented Mar 23, 2021

I'm trying to use spotty for the first time but I ran into an error after running spotty start and it tried to build my docker container:

 Step 2/5 : COPY requirements.txt requirements.txt
 COPY failed: file not found in build context or excluded by .dockerignore: stat requirements.txt: file does not exist

My directory structure

proj/
  docker/
    models.Dockerfile
  src/*
  requirements.txt
  spotty.yaml

Here's my dockerfile: docker/models.Dockerfile

FROM python:3.8.7-buster

COPY requirements.txt requirements.txt
RUN pip3 install -r requirements.txt

Here's my spotty config: spotty.yaml

project:
  name: model-server
  syncFilters:
    - exclude:
        - .idea/*
        - .git/*
        - .mypy_cache/*
        - '*/__pycache__/*'
        - '*/*.swp'
containers:
  - projectDir: /workspace/project
    file: docker/models.Dockerfile
    ports:
      # Server
      - containerPort: 5000
        hostPort: 5000
    volumeMounts:
      - name: workspace
        mountPath: /workspace
instances:
  - name: model-server-inst
    provider: aws
    parameters:
      region: us-east-2
      instanceType: t2.small
      dockerDataRoot: /
      volumes:
        - name: workspace
          parameters:
            size: 50
            deletionPolicy: retain
        - name: docker
          parameters:
            size: 10
            mountDir: /docker
            deletionPolicy: retain

I saw in the docs that Note: Spotty uses the directory with the Dockerfile as its build context.
So this seems like why I ran into this issue since the requirements.txt file is not present in the docker context.
And indeed, the command that spotty ran was
docker build -t spotty-model-server-model-server-inst-default:1616462585 -f /mnt/model-server-model-server-inst-workspace/project/docker/models.Dockerfile /mnt/ai-writer-model-server-ai-writer-model-server-inst-workspace/project/docker
whereas when I build my dockerfile locally, the last argument (the context) I would give to docker build is my root directory (/project), not /project/docker.

So is there a way to get around this, or does using spotty mean that I need to keep my dockerfile in my root directory? Or is there something I'm doing wrong.

@apls777
Copy link
Collaborator

apls777 commented Mar 23, 2021

So is there a way to get around this, or does using spotty mean that I need to keep my dockerfile in my root directory? Or is there something I'm doing wrong.`

Yes, you either should put the Dockerfile into the root directory of your project or copy the requirements.txt file inside the docker/ directory. In the first case, use a .dockerignore file to ignore potentially heavy directories that may slow down the building.

@himat
Copy link
Author

himat commented Mar 23, 2021

Would it be possible to add a way to specify a root build context?
My project has multiple components/servers each of which has their own dockerfile, which is why I put them all in a docker/ dir in the root of my project.
So putting all the dockerfiles in the root isn't that pleasant, nor would copying the requirements.txt into that folder manually make much sense.

@apls777
Copy link
Collaborator

apls777 commented Mar 26, 2021

Yes, it's possible, but I'm not sure when I will be able to have a look.

@himat
Copy link
Author

himat commented Mar 26, 2021

Not critical actually, I did what you said of putting the dockerfile in the root of the project. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants