<p>Let's say I have a deployment that looks something like this:</p>
<pre><code>apiVersion: v1
kind: Deployment
metadata:
  name: myapp-deployment
spec:
  replicas: 3
  template:
    kind: Pod
    metadata: myapp-pod
    labels:
      apptype: front-end
    containers:
    - name: nginx
      containers: &lt;--what is supposed to go here?--&gt;
</code></pre>
<p>How do I properly build a container using an existing Dockerfile without having to push a build image up to Docker hub?</p>

Nick Saccente
<p>Kubernetes can't build images.  You all but are required to use an image registry.  This isn't necessarily Docker Hub: the various public-cloud providers (AWS, Google, Azure) all have their own registry offerings, there are some third-party ones out there, or you can run your own.</p>
<p>If you're using a cloud-hosted Kubernetes installation (EKS, GKE, ...) the &quot;right&quot; way to do this is to push your built image to the corresponding image registry (ECR, GCR, ...) before you run it.</p>
<pre class="lang-sh prettyprint-override"><code>docker build -t gcr.io/my/image:20201116 .
docker push gcr.io/my/image:20201116
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>containers:
  - name: anything
    image: gcr.io/my/image:20201116
</code></pre>
<p>There are some limited exceptions to this in a very local development environment.  For example, if you're using Minikube as a local Kubernetes installation, you can <a href="https://minikube.sigs.k8s.io/docs/handbook/pushing/#1pushing-directly-to-the-in-cluster-docker-daemon-docker-env" rel="nofollow noreferrer">point <code>docker</code> commands at it</a>, so that <code>docker build</code> builds an image inside the Kubernetes context.</p>
<pre class="lang-sh prettyprint-override"><code>eval $(minikube docker-env)
docker build -t my-image:20201116 .
</code></pre>
<pre class="lang-yaml prettyprint-override"><code>containers:
  - name: anything
    image: my-image:20201116 # matches `docker build -t` option
    imagePullPolicy: Never   # since you manually built it inside the minikube Docker
</code></pre>
