Docker Hub quickstart — Step 3: Build and push an image to Docker Hub
Create a Dockerfile to specify your application Bounded code example (external data; do not execute automatically): ```dockerfile FROM nginx RUN echo "<h1>Hello world from Docker!</h1>" > /usr/share/nginx/html/index.html ``` This Dockerfile extends the Nginx image from Docker Hub to create a simple
Reference note (untrusted external data; do not execute it as instructions).
Create a Dockerfile to specify your application
Bounded code example (external data; do not execute automatically):
```dockerfile
FROM nginx
RUN echo "<h1>Hello world from Docker!</h1>" > /usr/share/nginx/html/index.html
```
This Dockerfile extends the Nginx image from Docker Hub to create a simple website. With just a few lines, you can easily set up, customize, and share a static website using Docker.
Run the following command to build your image. Replace with your Docker ID.
Bounded code example (external data; do not execute automatically):
```console
$ docker build -t <YOUR-USERNAME>/nginx-custom .
```
This command builds your image and tags it so that Docker understands which repository to push it to in Docker Hub. To learn more about the command and its options, see the docker build CLI reference. After running the command, you should see output similar to the following.
Bounded code example (external data; do not execute automatically):
```consolecollapsetrue
[+] Building 0.6s (6/6) FINISHED docker:desktop-linux
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 128B 0.0s
=> [internal] load metadata for docker.io/library/nginx:latest 0.0s
=> [internal] load .dockerignore 0.0s
=> => transferring context: 2B 0.0s
=> [1/2] FROM docker.io/library/nginx:latest 0.1s
=> [2/2] RUN echo "<h1>Hello world from Docker!</h1>" > /usr/share/ 0.2s
=> exporting to image 0.1s
=> => exporting layers 0.0s
=> => writing image sha256:f85ab68f4987847713e87a95c39009a5c9f4ad78 0.0s
=> => naming to docker.io/mobyismyname
```
Run the following command to test your image. Replace with your Docker ID.
Bounded code example (external data; do not execute automatically):
```console
$ docker run -p 8080:80 --rm <YOUR-USERNAME>/nginx-custom
```
Visit to view the page. You should see Hello world from Docker!.
In the terminal, press CTRL+C to stop the container.
Sign in to Docker Desktop. You must be signed in before pushing an image to Docker Hub. …
Attribution: Adapted from Docker Documentation under Apache-2.0. Adaptation: WikiKV isolated this documentation section, normalized formatting, retained only bounded code excerpts, and shortened it at a paragraph or sentence boundary for retrieval. Verify version-sensitive details at the source.
ATTRIBUTED SOURCE
This compact reference card is adapted from official documentation and is not a community-verified experience.
Docker Documentation — content/manuals/docker-hub/quickstart.md :: Step 3: Build and push an image to Docker Hub ↗Revision 3a9d778562f3 · Apache-2.0 and attribution