Parvez Mohammed
07/30/2025, 12:44 PMMarvin
07/30/2025, 12:44 PMMarvin
07/30/2025, 12:45 PMbash
# On the host machine, ensure you're logged in to your private registry
docker login <http://your-private-registry.com|your-private-registry.com>
This creates a ~/.docker/config.json
file with your credentials.
2. Mount Docker Config:
When starting your Prefect worker, mount the Docker config file:
bash
docker run -v ~/.docker/config.json:/root/.docker/config.json \
-v /var/run/docker.sock:/var/run/docker.sock \
prefecthq/prefect:2-python3.9 \
prefect worker start -p your-pool-name
3. Use Docker Credentials Helper:
If you're using a credentials helper on your host system, make sure it's also available in the Prefect container and properly configured.
4. Environment-based Authentication:
You can pass Docker authentication environment variables to your worker container:
bash
docker run -e DOCKER_USERNAME=your-username \
-e DOCKER_PASSWORD=your-password \
-v /var/run/docker.sock:/var/run/docker.sock \
prefecthq/prefect:2-python3.9 \
prefect worker start -p your-pool-name
The most secure and recommended approach is option 2 (mounting the Docker config), as it:
- Maintains security by using existing authentication
- Doesn't require storing credentials in environment variables
- Works consistently with various registry types
To verify this is working:
1. First, ensure you can pull the private image directly on your host machine
2. Test the authentication inside the Prefect worker container:
bash
docker exec -it your-prefect-worker-container docker pull your-private-image
If you're still experiencing issues after trying these solutions, please let me know:
1. Which approach you tried
2. The exact error message you're receiving
3. Whether you're using any specific Docker credential helpers or authentication methods on your host system
This will help me provide more targeted assistance for your specific setup.Parvez Mohammed
07/31/2025, 12:00 PMMarvin
07/31/2025, 12:01 PMMarvin
07/31/2025, 12:03 PMbash
prefect work-pool create "docker-pool" \
--type docker \
--base-job-template '{
"job_configuration": {
"docker": {
"auto_remove": true,
"volumes": ["/var/run/docker.sock:/var/run/docker.sock"]
}
}
}'
2. Set up authentication using environment variables:
When starting your worker container, include the registry authentication environment variables:
bash
docker run \
-e DOCKER_REGISTRY_URL=<http://your-registry.com|your-registry.com> \
-e DOCKER_USERNAME=your-username \
-e DOCKER_PASSWORD=your-password \
-e PREFECT_API_URL=your-prefect-api-url \
-v /var/run/docker.sock:/var/run/docker.sock \
prefecthq/prefect:2-python3.9 \
prefect worker start -p "docker-pool"
3. Alternative: Use Prefect Blocks for authentication:
You can create a Docker Registry credentials block in Prefect:
python
from prefect.blocks.docker import DockerRegistry
docker_registry_block = DockerRegistry(
username="your-username",
password="your-password",
registry_url="<http://your-registry.com|your-registry.com>"
)
docker_registry_block.save("my-private-registry")
4. In your deployment configuration:
python
from prefect import flow
from prefect.deployments import Deployment
@flow
def my_flow():
# your flow code here
pass
deployment = Deployment.build_from_flow(
flow=my_flow,
name="docker-deployment",
work_pool_name="docker-pool",
image="<http://your-private-registry.com/your-image:tag|your-private-registry.com/your-image:tag>"
)
The key points to understand:
- The Docker socket mount (/var/run/docker.sock
) allows the Prefect worker to communicate with the host's Docker daemon
- You don't need the Docker CLI inside the container because Prefect uses the Python Docker SDK to communicate directly with the Docker daemon through the socket
- Authentication credentials need to be available to the worker container through environment variables or Prefect blocks
If you're still experiencing issues, please:
1. Share the exact error message you're seeing
2. Confirm which registry you're using (Docker Hub, GitHub Container Registry, private registry, etc.)
3. Let me know if you're using any specific authentication method on your host system
This will help me provide more specific guidance for your setup.