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 Fletcher07 Jan 2025
Resolving Twig syntax errors in Drupal
The release of Drupal 10.4.0 sees stricter validation rules being applied to Twig templates, which can result in unexpected errors after an upgrade. One such issue involves the use of regular expressions within Twig's matches operator, leading to syntax errors that can break template rendering.This...