Skip to main content

Create and push to Docker Hub

Creating your own custom image... you need to have a Docker ID.  Not sure, well most likely you created it to download Docker Desktop.  If you don't have one, go to Docker and sign up.

In your  text editor create a file called Dockerfile in the same directory you want to have as your local site. No extension, just Dockerfile. Paste in this code and save the file:

FROM nginx:latest
COPY . /usr/share/nginx/html

This tells Docker to use the same nginx base image, and create a layer that adds in the HTML you created in the last step. Instead of creating a volume that accesses the file directly from the host you are running on, it adds the file to the image. To build the image, in your terminal, type:

docker image build --tag <YourDockerID>/firstimage .

A couple of steps here:

  1. Replace <YourDockerID> with your Docker ID.  Yes the one that you signed up for earlier.
  2. Notice the “.” at the end of the line. That tells Docker to build in the context of this directory. So when it looks to COPY the file to /usr/share/nginx/html it will use the file from this directory.

You can run it:

docker container run --name web -d -p 8080:80 <YourDockerID>/firstimage

And go to http://localhost:8080 to see the page.

Next login to Docker Hub. You can do this directly from Docker Desktop. Or you can do it from the command line by typing.

docker login

Finally push your image to Docker Hub:

docker image push <YourDockerID>/firstimage

Go to hub.docker.com and check your repositories.

Related articles

Andrew Fletcher18 Mar 2024
Resolving CVE-2022-48624 less issue
To resolve the CVE-2022-48624 vulnerability on Ubuntu using Nginx, it's crucial to understand that the issue lies within the "less" package, not Nginx itself. The vulnerability affects "less" before version 606, where close_altfile in filename.c in less omits shell_quote calls for LESSCLOSE,...