How can I tell docker to create a container from a local image, without looking at the docker hub if no local image is found with that name?

You don't have to name your images something esoteric.

Use a namespace

Just register a namespace on docker hub, and then use that in your image names. E.g., I am larsks on Docker Hub. Nobody but me can create an image in the larsks namespace, so if I name a local image larsks/example, I know that's never going to resolve on Docker Hub unless I put it there.

Use a bogus registry name

Maybe you don't want to register with Docker Hub.

Recall that the fully qualified form of an image name is registry/namespace/repository:tag. If you name your local images with a nonexistent registry, Docker won't be able to pull them from anywhere. E.g., if I name something dne/larsks/example (dne as in "does not exist", but anything works that isn't a valid hostname), Docker will never be able to pull this image.


Name your images with a registry or repository you control. In other words, don't run:

docker build -t example .

Because that gets expanded to a Docker Official Image repo (aka docker.io/library/) that you don't control. But you can create your own user account on Hub, allowing you to:

docker build -t ${your_hub_id}/example .

So that any image that doesn't exist locally tries to pull from your namespace on Hub.