<@ULVA73B9P> I am using a docker image and in my y...
# ask-marvin
b
@Marvin I am using a docker image and in my yaml file I have auto_remove: true but it is not removing containers
m
I see you're having trouble with Docker containers not being removed despite setting
auto_remove: true
in your YAML file. This could be due to a variety of reasons. Let's try to troubleshoot: 1. Check Docker version: Ensure you're using a Docker version that supports the
auto_remove
option. This feature was added in Docker API version 1.25 (Docker 1.13.0). 2. Correct Syntax: Make sure your YAML file is correctly formatted. The
auto_remove
option should be under the
container_config
section. 3. Running Containers: The
auto_remove
option only removes containers after they have stopped running. If your container is still running, it won't be removed. 4. Error in Container: If the container encounters an error and stops, Docker might not remove it to allow you to investigate the error. If none of these seem to be the issue, could you please share more details about your setup? That would help me assist you better.
b
@Marvin my deployment looks like this?
Copy code
deployments:
  - name: "dp_test::dev"
    version: 1.0
    description: ""
    tags: ["dev"]
    entrypoint: integrations/graph_api/deployments/check_microsoft_licenses.py:fl_check_microsoft_licenses
    parameters: {"min_max_method": "maximum"}
    work_pool:
      name: azure-docker-pool
      job_variables:
        image: "<http://asdf.azurecr.io/asdf/prefect:dev|asdf.azurecr.io/asdf/prefect:dev>"
        image_pull_policy: Always
        env:
          ENVIRONMENT: "dev"
          PREFECT_LOGGING_LEVEL: "DEBUG"
      auto_remove: true
    schedule: *1st_of_month_at_7am
m
I see. It seems like you're using Prefect for workflow orchestration and you're trying to auto-remove Docker containers after they finish running tasks. However, the
auto_remove
option you're using is not in the correct place. In Prefect, the
auto_remove
option is not a top-level configuration for a deployment. It should be under the
run_config
section of a task, which specifies the Docker image to use when running the task. Here's an example of how you might structure it:
Copy code
yaml
from prefect import Flow, task
from prefect.run_configs import DockerRun

@task(run_config=DockerRun(auto_remove=True))
def my_task():
    ...

with Flow("My flow") as flow:
    my_task()
In your case, you might need to adjust your Python scripts to include the
auto_remove
option in the
run_config
of your tasks. Please note that this is a feature of Prefect 0.14.0 and later, so make sure your Prefect version is up to date.
m
From the Prefect documentation, it seems that the
auto_remove
option is not directly available in the infrastructure block of a deployment. The infrastructure block is used to specify the infrastructure for flow runs created by the deployment at runtime. However, you can specify the environment in which the flow executes when you run a flow directly by calling the flow yourself. This might be where you can use Docker's
auto_remove
option. For more specific details, I would recommend checking the Prefect documentation or their community forum. Here are the links to the pages I found: - Infrastructure - Automations Please note that the information might not be complete as the excerpts are limited in length.