is there any guide to pulling a docker image from ...
# ask-community
a
is there any guide to pulling a docker image from a gcr registry with prefect-docker?
or perhaps a combination of prefect docker and prefect gcp
n
Looking for the answer to this as well. I'm try to do this in the prefect.yaml 'pull' step:
Copy code
pull:
- prefect_docker.images.pull_docker_image:
    requires: prefect-docker>=0.3.1
    repository: '{{ build_image.image_name }}'
    tag: '{{ build_image.tag }}'
    docker_registry_credentials: '{{ prefect.blocks.gcp-credentials.gcp-data-credentials }}'
1
But I keep getting this error:
Copy code
RuntimeError: Tasks cannot be run outside of a flow. To call the underlying task function outside of a flow use `task.fn()`.
1
j
Hey, pull steps occur once the python process has already started in the container. To use a specific image for a deployment from GCR you would specify it in your `prefect.yaml`:
Copy code
...
deployments:
- name: my-deployment
  work_pool:
    name: "my-work-pool"
    job_variables:
      image: <<GCR IMAGE URL GOES HERE>>
👍 1
n
Thank you @Jake Kaplan, will try it out and let you know!
@Jake Kaplan I'm still getting some errors, would I still need to define a pull step? This is my `prefect.yaml`:
Copy code
# Generic metadata about this project
name: data-scripts
prefect-version: 2.13.1

# build section allows you to manage and build docker images
build:
- prefect_docker.deployments.steps.build_docker_image:
    id: build_image
    requires: prefect-docker>=0.3.1
    image_name: '{{ prefect.variables.prefect_image_name }}'
    tag: latest
    dockerfile: Dockerfile

# push section allows you to manage if and how this project is uploaded to remote locations
push:
- prefect_docker.deployments.steps.push_docker_image:
    requires: prefect-docker>=0.3.1
    image_name: '{{ build_image.image_name }}'
    tag: '{{ build_image.tag }}'
    credentials: '{{ prefect.blocks.gcp-credentials.gcp-data-credentials }}'

# the deployments section allows you to provide configuration for deploying flows
deployments:
- name: lrp-deployment
  version:
  tags:
  - lrp
  description:
  schedule:
    cron: 00 20 * * 1-5
    timezone: America/Chicago
    day_or: true
  entrypoint: src/flow.py:run_lrp
  parameters: {}
  work_pool:
    name: data-scripts-workpool
    work_queue_name:
    job_variables: {}
  work_queue_name: default
  job_variables:
    image: '{{ build_image.image }}'
j
I think you still need to define a pull step in the yaml but if you're baking your code into the image it can usually be empty, unless you need to do things like set a working directory etc.
What errors are you seeing?
n
it forces me to set a working directory
and then when I do I'm getting a file not found error :
Copy code
FileNotFoundError: [Errno 2] No such file or directory: '/opt/prefect/src/flow.py'
I added this line to my Dockerfile as well
COPY . /opt/prefect
This is my Dockerfile @Jake Kaplan
Copy code
FROM python:3.9-slim AS base

#updating pip
RUN pip install --upgrade pip

#installing all dependencies
COPY requirements.txt .
RUN pip install -r requirements.txt

FROM base AS build

COPY . /opt/prefect

CMD ["python", "src/flow.py"]