Repository: PrefectHQ/prefect

Issue:
Local docker images should be available as base images for environments
Currently, it appears that building an image locally and specifying that as a base image for Docker-based environments does not work (it attempts to pull from remote registries).

We should find a way to fix this.

**cc:** @joshmeek 


Discussion:
Ah yes! Should have it check the local instance first before attempting to pull from a registry!
@cicdw We should revisit this
Yea agreed @joshmeek ; I'm thinking this won't actually be possible without pushing to a registry, and instead we might just revisit offering a keyword argument for custom docker files?  Either way it'd be nice to wrap this issue up.

Resolving patch:
diff --git a/src/prefect/environments/storage/docker.py b/src/prefect/environments/storage/docker.py
--- a/src/prefect/environments/storage/docker.py
+++ b/src/prefect/environments/storage/docker.py
@@ -40,6 +40,7 @@ class Docker(Storage):
         - prefect_version (str, optional): an optional branch, tag, or commit specifying the version of prefect
             you want installed into the container; defaults to the version you are currently using or `"master"` if your version is ahead of
             the latest tag
+        - local_image(bool, optional): an optional flag whether or not to use a local docker image, if True then a pull will not be attempted
     """
 
     def __init__(
@@ -53,6 +54,7 @@ def __init__(
         files: dict = None,
         base_url: str = "unix://var/run/docker.sock",
         prefect_version: str = None,
+        local_image: bool = False,
     ) -> None:
         self.registry_url = registry_url
 
@@ -72,6 +74,7 @@ def __init__(
         self.flows = dict()  # type: Dict[str, str]
         self._flows = dict()  # type: Dict[str, "prefect.core.flow.Flow"]
         self.base_url = base_url
+        self.local_image = local_image
 
         version = prefect.__version__.split("+")
         if prefect_version is None:
@@ -214,7 +217,7 @@ def build_image(self, push: bool = True) -> tuple:
         with tempfile.TemporaryDirectory() as tempdir:
 
             # Build the dockerfile
-            if self.base_image:
+            if self.base_image and not self.local_image:
                 self.pull_image()
 
             self.create_dockerfile_object(directory=tempdir)


Test patch:
diff --git a/tests/environments/storage/test_docker_storage.py b/tests/environments/storage/test_docker_storage.py
--- a/tests/environments/storage/test_docker_storage.py
+++ b/tests/environments/storage/test_docker_storage.py
@@ -44,6 +44,7 @@ def test_empty_docker_storage():
     assert not storage.files
     assert storage.prefect_version
     assert storage.base_url == "unix://var/run/docker.sock"
+    assert not storage.local_image
 
 
 @pytest.mark.parametrize("version_info", [(3, 5), (3, 6), (3, 7)])
@@ -78,6 +79,7 @@ def test_initialized_docker_storage():
         env_vars={"test": "1"},
         base_url="test_url",
         prefect_version="my-branch",
+        local_image=True,
     )
 
     assert storage.registry_url == "test1"
@@ -88,6 +90,7 @@ def test_initialized_docker_storage():
     assert storage.env_vars == {"test": "1"}
     assert storage.base_url == "test_url"
     assert storage.prefect_version == "my-branch"
+    assert storage.local_image
 
 
 def test_files_not_absolute_path():