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
Used demo static webpage for testing.
Created Dockerfile
💡 It should be Dockerfile, no extension. Dockerfile.Dockerfile is incorrect!
Used nginx Alpine as server and the following code:
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:
Is there a way to push pre-existing packages?
Error Pushing to Docker Hub
An image does not exist locally with the tag username/staticapptest
Also the same error for:
Image IDs that I know exist. (See below)
It seems to ignore my attempts of the default tag(s) and latest. Access is denied, despite being logged in on Docker in VS Code and Docker Desktop. Logging out / in again doesn't solve the issue.
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:
Package app
Run image
Take the image ID and run within a container
776442dod12 libtest:latest "nginx -g 'daemon of…" 18 seconds ago Up 13 seconds 0.0.0.0:80->80/tcp hopeful_thompson
Commit the container
docker commit 796442dod12 <name>/libtest:<tag>
There are some docker image reveals;
libtest latest 776442dod12 25 hours ago 29.4MB
Then it was pushed to the hub; Check it out here.
What went wrong? I had to make the image a container first. I thought the image would be enough.