<p><a href="https://i.stack.imgur.com/gVffU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gVffU.png" alt="This is the image of the steps that needs to be done using a dockerfile and a kubernetes file." /></a></p>
<p><a href="https://i.stack.imgur.com/xm0GC.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xm0GC.png" alt="This is the Dockerfile that I have written to perform the tasks but it's not running properly and I am not able to figure out the error." /></a></p>
<p>I will be very thankful if anybody can help me out with this dockerfile and kubernetes conf file to perform the following tasks.
I wanted to create a Dockerfile which can fetch the source code of an angular app from github and build it and also push it to the docker hub.
I have tried with the Dockerfile below but there are issues with the file. If anyone can guide me to the mistakes I have done or can provide a suitable Docker file then it will be great.
Also If possible I also want to ask for the kubernetes conf file which can pull the image from the dockerhub and run it as a service.
Thank You.</p>

<p>Assuming that you have Docker and Kubernetes solutions setup and ready.</p>
<p>First, as mentioned by the others, the best option is just to use <a href="https://github.com/wkrzywiec/aston-villa-app/blob/master/Dockerfile" rel="nofollow noreferrer">Dockerfile from the repo</a> instead of writing your own:</p>
<pre><code>### STAGE 1: Build ###
FROM node:12.7-alpine AS build
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build

### STAGE 2: Run ###
FROM nginx:1.17.1-alpine
COPY nginx.conf /etc/nginx/nginx.conf
COPY --from=build /usr/src/app/dist/aston-villa-app /usr/share/nginx/html
</code></pre>
<p>Please <a href="https://github.com/wkrzywiec/aston-villa-app" rel="nofollow noreferrer">clone the repo</a>:</p>
<pre><code>git clone https://github.com/wkrzywiec/aston-villa-app.git
cd aston-villa-app
</code></pre>
<p>Create your Docker repository - steps are <a href="https://docs.docker.com/docker-hub/repos/" rel="nofollow noreferrer">presented here</a> - in this example I will create a public repository named <code>testing-aston-villa-app</code>.</p>
<p>Login to the <a href="https://docs.docker.com/engine/reference/commandline/login/" rel="nofollow noreferrer">Docker registry</a> on your host:</p>
<pre class="lang-sh prettyprint-override"><code>docker login
...
Login Succeeded
</code></pre>
<p><a href="https://docs.docker.com/docker-hub/#step-4-build-and-push-a-container-image-to-docker-hub-from-your-computer" rel="nofollow noreferrer">Build and push Docker image to your repo - commands are like this</a>:</p>
<pre class="lang-sh prettyprint-override"><code>docker build -t &lt;your_username&gt;/my-private-repo .
docker push &lt;your_username&gt;/my-private-repo
</code></pre>
<p>In our example (make sure that you are in the directory where repo is cloned):</p>
<pre class="lang-sh prettyprint-override"><code>docker build -t {your-username}/testing-aston-villa-app .
docker push {your-username}/testing-aston-villa-app
</code></pre>
<p>Ok, image is now on your Docker repository. Time to use it in Kubernetes. Please do below instructions on the host where you <a href="https://kubernetes.io/docs/reference/kubectl/overview/" rel="nofollow noreferrer">have <code>kubectl</code> installed and configured to interact with your cluster</a>.</p>
<p>Following yaml file has definitions for <a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/" rel="nofollow noreferrer">deployment</a>  and for <a href="https://kubernetes.io/docs/concepts/services-networking/service/" rel="nofollow noreferrer">service</a>. In <code>image</code> field please use <code>&lt;your_username&gt;/my-private-repo</code> name:</p>
<pre class="lang-yaml prettyprint-override"><code>apiVersion: apps/v1
kind: Deployment
metadata:
  name: aston-villa-app-deployment
spec:
  selector:
    matchLabels:
      app: aston-villa-app
  replicas: 2
  template:
    metadata:
      labels:
        app: aston-villa-app
    spec:
      containers:
      - name: aston-villa-app
        image: {your-username}/testing-aston-villa-app
        ports:
        - containerPort: 80
---
apiVersion: v1
kind: Service
metadata:
  name: aston-villa-app-service
spec:
  selector:
    app: aston-villa-app
  ports:
    - protocol: TCP
      port: 80
      targetPort: 80
</code></pre>
<p>Please save this yaml and run <code>kubectl apply -f {file.yaml}</code>.</p>
<p>After applied, check if pods are up and service exits:</p>
<pre><code>kubectl get pods,svc
NAME                                                  READY   STATUS      RESTARTS        AGE
pod/aston-villa-app-deployment-5f5478b66d-592nd       1/1     Running     0               13m
pod/aston-villa-app-deployment-5f5478b66d-vvhq2       1/1     Running     0               13m

NAME                              TYPE        CLUSTER-IP       EXTERNAL-IP   PORT(S)     AGE
service/aston-villa-app-service   ClusterIP   10.101.176.184   &lt;none&gt;        80/TCP      13m
</code></pre>
<p>Now, let's check if service is working by making request to it from another pod:</p>
<pre class="lang-sh prettyprint-override"><code>kubectl run -i --tty busybox --image=busybox -- sh
If you don't see a command prompt, try pressing enter.
/ # wget 10.101.176.184
Connecting to 10.101.176.184 (10.101.176.184:80)
saving to 'index.html'
index.html           100% |*****************************************************************************|   596  0:00:00 ETA
'index.html' saved
/ # cat index.html 
&lt;!doctype html&gt;
&lt;html lang=&quot;en&quot;&gt;
&lt;head&gt;
  &lt;meta charset=&quot;utf-8&quot;&gt;
  &lt;title&gt;AstonVillaApp&lt;/title&gt;
  &lt;base href=&quot;/&quot;&gt;

  &lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1&quot;&gt;
  &lt;link rel=&quot;icon&quot; type=&quot;image/x-icon&quot; href=&quot;assets/images/as_logo.svg&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;app-root&gt;&lt;/app-root&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;runtime.js&quot;&gt;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;polyfills.js&quot;&gt;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;styles.js&quot;&gt;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;vendor.js&quot;&gt;&lt;/script&gt;&lt;script type=&quot;text/javascript&quot; src=&quot;main.js&quot;&gt;&lt;/script&gt;&lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>Note that I used IP address <code>10.101.176.184</code> because it's the IP address of the <code>service/aston-villa-app-service</code>. In your case, it will be probably different.</p>
