Find a better formatted version of this post on Notion! Share it. Share this too. The more sharing, the better.
Packaging the app: ✅ Pushing to DockerHub: ✅
See Error Pushing to Docker Hub below for how I troubleshot the issue!
What is my app?
A static webpage I had created for fun a few months ago. I knew it would come in handy!
What did I do?
- 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;"]
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.
- Exposed port 80
- Created image;
Pushing the Image
Had to re-package it; 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.
Yes, it is different than the image above, but it does exist.
- New images created
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 and logging in doesn’t solve this.
Why?
The Fix
- Creating the image as a container and then pushing it works
Steps Taken:
- Package app (above)
- Run the 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 776442dod12 <name>/libtest:<tag>
- 5
docker images
reveals;
libtest latest 776442dod12 25 hours ago 29.4MB
- Then I push it to my DockerHub;
docker push <name>/libtest:<tag>
The push refers to repository [docker.io/<name>/libtest]
And it works; Check it out publicly here.
What went wrong?
I had to make the image a container first. I thought the image would be enough.
Resources used:
- Host Your Static Website in Azure as a Docker Container
- Docker for Beginners: From Desktop to Deployment
- How to Safely Push Docker Images (modified the instructions for Windows)
Find me on Twitter, or my blog. You can Buy Me A Coffee and help me keep writing!
Comments
Post a Comment