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 Fletcher04 Apr 2025
Managing .gitignore changes
When working with Git, the .gitignore file plays a critical role in controlling which files and folders are tracked by version control. Yet, many developers are unsure when changes to .gitignore take effect and how to manage files that are already being tracked. This uncertainty can lead to...
Andrew Fletcher26 Mar 2025
How to fix the ‘Undefined function t’ error in Drupal 10 or 11 code
Upgrading to Drupal 10.4+ you might have noticed a warning in their code editor stating “Undefined function ‘t’”. While Drupal’s `t()` function remains valid in procedural code, some language analysis tools — such as Intelephense — do not automatically recognise Drupal’s global functions. This...
Andrew Fletcher17 Mar 2025
Upgrading to PHP 8.4 challenges with Drupal contrib modules
The upgrade from PHP 8.3.14 to PHP 8.4.4 presents challenges for Drupal 10.4 websites, particularly when dealing with contributed modules. While Drupal core operates seamlessly, various contrib modules have not yet been updated to accommodate changes introduced in PHP 8.4.x. This has resulted in...