|
1 | 1 | --- |
2 | 2 | description: Learn how to get started using Docker Hub |
3 | | -keywords: Docker, docker, registry, accounts, plans, Dockerfile, Docker Hub, accounts, |
4 | | - organizations, repositories, groups, teams |
| 3 | +keywords: Docker Hub, push image, pull image, repositories |
5 | 4 | title: Docker Hub quickstart |
6 | 5 | linkTitle: Quickstart |
7 | 6 | weight: 10 |
8 | 7 | --- |
9 | 8 |
|
10 | | -The following section contains step-by-step instructions on how to get started with Docker Hub. |
| 9 | +Docker Hub provides a vast library of pre-built images and resources, |
| 10 | +accelerating development workflows and reducing setup time. You can build upon |
| 11 | +pre-built images from Docker Hub and then use repositories to share and |
| 12 | +distribute your own images with your team or millions of other developers. |
11 | 13 |
|
12 | | -### Step 1: Sign up for a free Docker account |
| 14 | +This guide shows you how to find and run a pre-built image. It then walks you |
| 15 | +through creating a custom image and sharing it through Docker Hub. |
13 | 16 |
|
14 | | -Start by creating a [Docker ID](https://hub.docker.com/signup). |
| 17 | +## Prerequisites |
15 | 18 |
|
16 | | -A [Docker ID](/accounts/create-account/) grants you access to Docker Hub repositories and lets you explore available images from the community and verified publishers. You also need a Docker ID to share images on Docker Hub. |
| 19 | +- [Download and install Docker](../../get-started/get-docker.md) |
| 20 | +- [Create a Docker account](https://app.docker.com/signup) |
17 | 21 |
|
18 | | -> [!TIP] |
19 | | -> |
20 | | -> Explore [Docker's core subscriptions](https://www.docker.com/pricing/) to see what else Docker can offer you. |
| 22 | +## Step 1: Find an image in Docker Hub's library |
21 | 23 |
|
22 | | -### Step 2: Create your first repository |
| 24 | +You can search for content in Docker Hub itself, in the Docker Desktop |
| 25 | +Dashboard, or by using the `docker search` CLI command. Searching on Docker Hub |
| 26 | +itself offers the most options to explore content. |
23 | 27 |
|
24 | | -To create a repository: |
| 28 | +To search or browse for content on Docker Hub: |
25 | 29 |
|
26 | | -1. Sign in to [Docker Hub](https://hub.docker.com). |
27 | | -2. On the Repositories page, select **Create repository**. |
28 | | -3. Name it **<your-username>/my-private-repo**. |
29 | | -4. Set the visibility to **Private**. |
30 | | -5. Select **Create**. |
| 30 | +1. Navigate to the [Docker Hub Explore page](https://hub.docker.com/explore). |
31 | 31 |
|
32 | | -You've created your first repository. |
| 32 | + On the Explore page, you can browse by catalog or category, or use the search |
| 33 | + to quickly find content. |
33 | 34 |
|
34 | | -### Step 3: Download and install Docker Desktop |
| 35 | +2. Under **Categories**, select **Web servers**. |
35 | 36 |
|
36 | | -You need to download Docker Desktop to build, push, and pull container images. |
| 37 | + After the results are displayed, you can further filter the results using the |
| 38 | + filters on the left side of the page. |
37 | 39 |
|
38 | | -1. Download and install [Docker Desktop](/manuals/desktop/_index.md). |
| 40 | +3. In the filters, select **Docker Official Image**. |
39 | 41 |
|
40 | | -2. Sign in to Docker Desktop using the Docker ID you created in step one. |
| 42 | + Filtering by Trusted Content ensures that you see only high-quality, secure |
| 43 | + images curated by Docker and verified publishing partners. |
41 | 44 |
|
42 | | -### Step 4: Pull and run a container image from Docker Hub |
| 45 | +4. In the results, select the **nginx** image. |
43 | 46 |
|
44 | | -1. In your terminal, run `docker pull hello-world` to pull the image from Docker Hub. You should see output similar to: |
| 47 | + Selecting the image opens the image's page where you can learn more about how |
| 48 | + to use the image. On the page, you'll also find the `docker pull` command to |
| 49 | + pull the image. |
| 50 | + |
| 51 | +Now that you've found an image, it's time to pull and run it on your device. |
| 52 | + |
| 53 | +## Step 2: Pull and run an image from Docker Hub |
| 54 | + |
| 55 | +1. In your terminal, run the following command to pull and run the Nginx image. |
45 | 56 |
|
46 | 57 | ```console |
47 | | - $ docker pull hello-world |
48 | | - Using default tag: latest |
49 | | - latest: Pulling from library/hello-world |
50 | | - 2db29710123e: Pull complete |
51 | | - Digest: sha256:7d246653d0511db2a6b2e0436cfd0e52ac8c066000264b3ce63331ac66dca625 |
52 | | - Status: Downloaded newer image for hello-world:latest |
53 | | - docker.io/library/hello-world:latest |
| 58 | + $ docker run -p 8080:80 --rm nginx |
54 | 59 | ``` |
55 | 60 |
|
56 | | -2. Run `docker run hello-world` to run the image locally. You should see output similar to: |
57 | | - |
58 | | - ```console |
59 | | - $ docker run hello-world |
60 | | - Hello from Docker! |
61 | | - This message shows that your installation appears to be working correctly. |
| 61 | + The `docker run` command automatically pulls and runs the image without the |
| 62 | + need to run `docker pull` first. To learn more about the command and its |
| 63 | + options, see the [`docker run` CLI |
| 64 | + reference](../../reference/cli/docker/container/run.md). After running the |
| 65 | + command, you should see output similar to the following. |
| 66 | + |
| 67 | + ```console {collapse=true} |
| 68 | + Unable to find image 'nginx:latest' locally |
| 69 | + latest: Pulling from library/nginx |
| 70 | + a480a496ba95: Pull complete |
| 71 | + f3ace1b8ce45: Pull complete |
| 72 | + 11d6fdd0e8a7: Pull complete |
| 73 | + f1091da6fd5c: Pull complete |
| 74 | + 40eea07b53d8: Pull complete |
| 75 | + 6476794e50f4: Pull complete |
| 76 | + 70850b3ec6b2: Pull complete |
| 77 | + Digest: sha256:28402db69fec7c17e179ea87882667f1e054391138f77ffaf0c3eb388efc3ffb |
| 78 | + Status: Downloaded newer image for nginx:latest |
| 79 | + /docker-entrypoint.sh: /docker-entrypoint.d/ is not empty, will attempt to perform configuration |
| 80 | + /docker-entrypoint.sh: Looking for shell scripts in /docker-entrypoint.d/ |
| 81 | + /docker-entrypoint.sh: Launching /docker-entrypoint.d/10-listen-on-ipv6-by-default.sh |
| 82 | + 10-listen-on-ipv6-by-default.sh: info: Getting the checksum of /etc/nginx/conf.d/default.conf |
| 83 | + 10-listen-on-ipv6-by-default.sh: info: Enabled listen on IPv6 in /etc/nginx/conf.d/default.conf |
| 84 | + /docker-entrypoint.sh: Sourcing /docker-entrypoint.d/15-local-resolvers.envsh |
| 85 | + /docker-entrypoint.sh: Launching /docker-entrypoint.d/20-envsubst-on-templates.sh |
| 86 | + /docker-entrypoint.sh: Launching /docker-entrypoint.d/30-tune-worker-processes.sh |
| 87 | + /docker-entrypoint.sh: Configuration complete; ready for start up |
| 88 | + 2024/11/07 21:43:41 [notice] 1#1: using the "epoll" event method |
| 89 | + 2024/11/07 21:43:41 [notice] 1#1: nginx/1.27.2 |
| 90 | + 2024/11/07 21:43:41 [notice] 1#1: built by gcc 12.2.0 (Debian 12.2.0-14) |
| 91 | + 2024/11/07 21:43:41 [notice] 1#1: OS: Linux 6.10.11-linuxkit |
| 92 | + 2024/11/07 21:43:41 [notice] 1#1: getrlimit(RLIMIT_NOFILE): 1048576:1048576 |
| 93 | + 2024/11/07 21:43:41 [notice] 1#1: start worker processes |
| 94 | + 2024/11/07 21:43:41 [notice] 1#1: start worker process 29 |
| 95 | + ... |
| 96 | + ``` |
62 | 97 |
|
63 | | - To generate this message, Docker took the following steps: |
64 | | - 1. The Docker client contacted the Docker daemon. |
65 | | - 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. |
66 | | - (amd64) |
67 | | - 3. The Docker daemon created a new container from that image which runs the |
68 | | - executable that produces the output you are currently reading. |
69 | | - 4. The Docker daemon streamed that output to the Docker client, which sent |
70 | | - it to your terminal. |
| 98 | +2. Visit [https://localhost:8080](https://localhost:8080) to view the default |
| 99 | + Nginx page and verify that the container is running. |
71 | 100 |
|
72 | | - To try something more ambitious, you can run an Ubuntu container with: |
73 | | - $ docker run -it ubuntu bash |
| 101 | +3. In the terminal, press CTRL+C to stop the container. |
74 | 102 |
|
75 | | - Share images, automate workflows, and more with a free Docker ID: |
76 | | - https://hub.docker.com/ |
| 103 | +You've now run a web server without any set up or configuration, all from a |
| 104 | +single command. Docker Hub provides instant access to pre-built, ready-to-use |
| 105 | +container images, letting you quickly pull and run applications without needing |
| 106 | +to install or configure software manually. With Docker Hub's vast library of |
| 107 | +images, you can experiment with and deploy applications effortlessly, boosting |
| 108 | +productivity and making it easy to try out new tools, set up development |
| 109 | +environments, or build on top of existing software. |
77 | 110 |
|
78 | | - For more examples and ideas, visit: |
79 | | - https://docs.docker.com/get-started/ |
80 | | - ``` |
| 111 | +You can also extend images from Docker Hub, letting you quickly build and |
| 112 | +customize your own images to suit specific needs. |
81 | 113 |
|
82 | | -### Step 5: Build and push a container image to Docker Hub from your computer |
| 114 | +## Step 3: Build and push an image to Docker Hub |
83 | 115 |
|
84 | | -1. Start by creating a [Dockerfile](/reference/dockerfile.md) to specify your application as shown below: |
| 116 | +1. Create a [Dockerfile](/reference/dockerfile.md) to specify your application: |
85 | 117 |
|
86 | 118 | ```dockerfile |
87 | | - # syntax=docker/dockerfile:1 |
88 | | - FROM busybox |
89 | | - CMD echo "Hello world! This is my first Docker image." |
| 119 | + FROM nginx |
| 120 | + RUN echo "<h1>Hello world from Docker!</h1>" > /usr/share/nginx/html/index.html |
| 121 | + ``` |
| 122 | + |
| 123 | + This Dockerfile extends the Nginx image from Docker Hub to create a |
| 124 | + simple website. With just a few lines, you can easily set up, customize, and |
| 125 | + share a static website using Docker. |
| 126 | + |
| 127 | +2. Run the following command to build your image. Replace `<YOUR-USERNAME>` with your Docker ID. |
| 128 | + |
| 129 | + ```console |
| 130 | + $ docker build -t <YOUR-USERNAME>/nginx-custom . |
| 131 | + ``` |
| 132 | + |
| 133 | + This command builds your image and tags it so that Docker understands which |
| 134 | + repository to push it to in Docker Hub. To learn more about the command and |
| 135 | + its options, see the [`docker build` CLI |
| 136 | + reference](../../reference/cli/docker/buildx/build.md). After running the |
| 137 | + command, you should see output similar to the following. |
| 138 | + |
| 139 | + ```console {collapse=true} |
| 140 | + [+] Building 0.6s (6/6) FINISHED docker:desktop-linux |
| 141 | + => [internal] load build definition from Dockerfile 0.0s |
| 142 | + => => transferring dockerfile: 128B 0.0s |
| 143 | + => [internal] load metadata for docker.io/library/nginx:latest 0.0s |
| 144 | + => [internal] load .dockerignore 0.0s |
| 145 | + => => transferring context: 2B 0.0s |
| 146 | + => [1/2] FROM docker.io/library/nginx:latest 0.1s |
| 147 | + => [2/2] RUN echo "<h1>Hello world from Docker!</h1>" > /usr/share/ 0.2s |
| 148 | + => exporting to image 0.1s |
| 149 | + => => exporting layers 0.0s |
| 150 | + => => writing image sha256:f85ab68f4987847713e87a95c39009a5c9f4ad78 0.0s |
| 151 | + => => naming to docker.io/mobyismyname/nginx-custom 0.0s |
| 152 | + ``` |
| 153 | + |
| 154 | +3. Run the following command to test your image. Replace `<YOUR-USERNAME>` with |
| 155 | + your Docker ID. |
| 156 | + |
| 157 | + ```console |
| 158 | + $ docker run -p 8080:80 --rm <YOUR-USERNAME>/nginx-custom |
90 | 159 | ``` |
91 | 160 |
|
92 | | -2. Run `docker build -t <your_username>/my-private-repo .` to build your Docker |
93 | | - image. |
| 161 | +4. Visit [https://localhost:8080](https://localhost:8080) to view the page. You |
| 162 | + should see `Hello world from Docker!`. |
| 163 | + |
| 164 | +5. In the terminal, press CTRL+C to stop the container. |
94 | 165 |
|
95 | | -3. Run `docker run <your_username>/my-private-repo` to test your |
96 | | -Docker image locally. |
| 166 | +6. Sign in to Docker Desktop. You must be signed in before pushing an image to |
| 167 | + Docker Hub. |
97 | 168 |
|
98 | | -4. Run `docker push <your_username>/my-private-repo` to push your Docker image to Docker Hub. You should see output similar to: |
| 169 | +7. Run the following command to push your image to Docker Hub. Replace `<YOUR-USERNAME>` with your Docker ID. |
99 | 170 |
|
100 | 171 | ```console |
101 | | - $ cat > Dockerfile <<EOF |
102 | | - FROM busybox |
103 | | - CMD echo "Hello world! This is my first Docker image." |
104 | | - EOF |
105 | | - $ docker build -t mobythewhale/my-private-repo . |
106 | | - [+] Building 1.2s (5/5) FINISHED |
107 | | - => [internal] load build definition from Dockerfile |
108 | | - => => transferring dockerfile: 110B |
109 | | - => [internal] load .dockerignore |
110 | | - => => transferring context: 2B |
111 | | - => [internal] load metadata for docker.io/library/busybox:latest |
112 | | - => CACHED [1/1] FROM docker.io/library/busybox@sha256:a9286defaba7n3a519 |
113 | | - => exporting to image |
114 | | - => => exporting layers |
115 | | - => => writing image sha256:dcdb1fd928bf257bfc0122ea47accd911a3a386ce618 |
116 | | - => => naming to docker.io/mobythewhale/my-private-repo |
117 | | - $ docker run mobythewhale/my-private-repo |
118 | | - Hello world! This is my first Docker image. |
119 | | - $ docker push mobythewhale/my-private-repo |
120 | | - The push refers to repository [docker.io/mobythewhale/my-private-repo] |
121 | | - d2421964bad1: Layer already exists |
122 | | - latest: digest: sha256:7604fbf8eeb03d866fd005fa95cdbb802274bf9fa51f7dafba6658294 |
123 | | - efa9baa size: 526 |
| 172 | + $ docker push <YOUR-USERNAME>/nginx-custom |
124 | 173 | ``` |
125 | 174 |
|
126 | | - >**Note** |
127 | | - > |
128 | | - > You must be signed in to Docker Hub through Docker Desktop or the command line, and you must also name your images correctly, as per the above steps. |
| 175 | + The command pushes the image to Docker Hub and automatically |
| 176 | + creates the repository if it doesn't exist. To learn more about the command, |
| 177 | + see the [`docker push` CLI |
| 178 | + reference](../../reference/cli/docker/image/push.md). After running the |
| 179 | + command, you should see output similar to the following. |
| 180 | + |
| 181 | + ```console {collapse=true} |
| 182 | + Using default tag: latest |
| 183 | + The push refers to repository [docker.io/mobyismyname/nginx-custom] |
| 184 | + d0e011850342: Pushed |
| 185 | + e4e9e9ad93c2: Mounted from library/nginx |
| 186 | + 6ac729401225: Mounted from library/nginx |
| 187 | + 8ce189049cb5: Mounted from library/nginx |
| 188 | + 296af1bd2844: Mounted from library/nginx |
| 189 | + 63d7ce983cd5: Mounted from library/nginx |
| 190 | + b33db0c3c3a8: Mounted from library/nginx |
| 191 | + 98b5f35ea9d3: Mounted from library/nginx |
| 192 | + latest: digest: sha256:7f5223ae866e725a7f86b856c30edd3b86f60d76694df81d90b08918d8de1e3f size: 1985 |
| 193 | + ``` |
| 194 | + |
| 195 | + Now that you've created a repository and pushed your image, it's time to view |
| 196 | + your repository and explore its options. |
| 197 | + |
| 198 | +## Step 4: View your repository on Docker Hub and explore options |
| 199 | + |
| 200 | +1. Go to [Docker Hub](https://hub.docker.com) and sign in. |
129 | 201 |
|
130 | | -5. Your repository in Docker Hub should now display a new `latest` tag under **Tags**: |
| 202 | + After signing in, you should be on the **Repositories** page. If not, then go |
| 203 | + to the [**Repositories**](https://hub.docker.com/repositories/) page. |
131 | 204 |
|
132 | | -  |
| 205 | +2. Find the **nginx-custom** repository and select that row. |
133 | 206 |
|
134 | | -You've successfully: |
| 207 | + After selecting the repository, you should see more details and options for |
| 208 | + your repository. |
135 | 209 |
|
136 | | -- Signed up for a Docker account |
137 | | -- Created your first repository |
138 | | -- Pulled an existing container image from Docker Hub |
139 | | -- Built your own container image on your computer |
140 | | -- Pushed it successfully to Docker Hub |
| 210 | +You've now verified that your repository exists on Docker Hub, and you've |
| 211 | +discovered more options for it. View the next steps to learn more about some of |
| 212 | +these options. |
141 | 213 |
|
142 | | -### Next steps |
| 214 | +## Next steps |
143 | 215 |
|
144 | | -- Create an [organization](orgs.md) to use Docker Hub with your team. |
145 | | -- Automatically build container images from code through [builds](builds/_index.md). |
146 | | -- [Explore](https://hub.docker.com/explore) official & publisher images. |
147 | | -- [Upgrade your subscription](https://www.docker.com/pricing) to push additional private Docker images to |
148 | | -Docker Hub. |
| 216 | +- Automatically build container images from code through |
| 217 | + [builds](builds/_index.md). |
| 218 | +- Use [webhooks](./webhooks.md) to cause an action in another service in |
| 219 | + response to a push event in the repository. |
| 220 | +- Manage [repository settings](./repos/_index.md) to set the default privacy for |
| 221 | + your repositories. |
0 commit comments