Packaging an App with Dockerfile

 By Morgan Lucas

This is a post intended for this site, as a way to get a feel of using it consistently. Older posts are here.

Packaging the app: ✅ Pushing to DockerHub: ✅

See Error Pushing to Docker Hub below for how I troubleshot the issue!

My app is a static webpage I created for fun a few months ago (at the time of writing).

What I Did

💡 It should be Dockerfile, no extension. Dockerfile.Dockerfile is incorrect!

FROM scratch as static-site

WORKDIR /app


COPY . . 


FROM nginx:1.16.0-alpine as server


COPY --from=static-site /app /usr/share/nginx/html


EXPOSE 80


CMD [ "nginx", "-g", "daemon off;"]

This code is based off of a code by From Mwiza Kumwenda (see resources below).


I wondered if I should use "start" in the CMD [ "nginx", "-g", "daemon off;"] list/tuple, but it worked without it.

Expose port 80, and the following image was created.

It's quite long; Click it to see the full image. Note the repo staticapptest

Questions:

Error Pushing to Docker Hub

An image does not exist locally with the tag username/staticapptest

Also the same error for:

The Fix in Pushing to DockerHub

Creating the image as a container and then pushing it works. Steps to creat the image as a container and run it:

776442dod12   libtest:latest   "nginx -g 'daemon of…"   18 seconds ago   Up 13 seconds   0.0.0.0:80->80/tcp   hopeful_thompson

docker commit 796442dod12   <name>/libtest:<tag>

libtest            latest    776442dod12   25 hours ago     29.4MB


What went wrong? I had to make the image a container first. I thought the image would be enough.