github.com/dpiddy/docker@v1.12.2-rc1/docs/tutorials/dockerimages.md (about) 1 <!--[metadata]> 2 +++ 3 aliases = [ 4 "/engine/userguide/containers/dockerimages/", 5 "/engine/userguide/dockerimages/" 6 ] 7 title = "Build your own images" 8 description = "How to work with Docker images." 9 keywords = ["documentation, docs, the docker guide, docker guide, docker, docker platform, docker.io, Docker images, Docker image, image management, Docker repos, Docker repositories, docker, docker tag, docker tags, Docker Hub, collaboration"] 10 [menu.main] 11 parent = "engine_learn_menu" 12 weight = -4 13 +++ 14 <![end-metadata]--> 15 16 # Build your own images 17 18 Docker images are the basis of containers. Each time you've used `docker run` 19 you told it which image you wanted. In the previous sections of the guide you 20 used Docker images that already exist, for example the `ubuntu` image and the 21 `training/webapp` image. 22 23 You also discovered that Docker stores downloaded images on the Docker host. If 24 an image isn't already present on the host then it'll be downloaded from a 25 registry: by default the [Docker Hub Registry](https://hub.docker.com). 26 27 In this section you're going to explore Docker images a bit more 28 including: 29 30 * Managing and working with images locally on your Docker host. 31 * Creating basic images. 32 * Uploading images to [Docker Hub Registry](https://hub.docker.com). 33 34 ## Listing images on the host 35 36 Let's start with listing the images you have locally on our host. You can 37 do this using the `docker images` command like so: 38 39 $ docker images 40 41 REPOSITORY TAG IMAGE ID CREATED SIZE 42 ubuntu 14.04 1d073211c498 3 days ago 187.9 MB 43 busybox latest 2c5ac3f849df 5 days ago 1.113 MB 44 training/webapp latest 54bb4e8718e8 5 months ago 348.7 MB 45 46 You can see the images you've previously used in the user guide. 47 Each has been downloaded from [Docker Hub](https://hub.docker.com) when you 48 launched a container using that image. When you list images, you get three crucial pieces of information in the listing. 49 50 * What repository they came from, for example `ubuntu`. 51 * The tags for each image, for example `14.04`. 52 * The image ID of each image. 53 54 > **Tip:** 55 > You can use [a third-party dockviz tool](https://github.com/justone/dockviz) 56 > or the [Image layers site](https://imagelayers.io/) to display 57 > visualizations of image data. 58 59 A repository potentially holds multiple variants of an image. In the case of 60 our `ubuntu` image you can see multiple variants covering Ubuntu 10.04, 12.04, 61 12.10, 13.04, 13.10 and 14.04. Each variant is identified by a tag and you can 62 refer to a tagged image like so: 63 64 ubuntu:14.04 65 66 So when you run a container you refer to a tagged image like so: 67 68 $ docker run -t -i ubuntu:14.04 /bin/bash 69 70 If instead you wanted to run an Ubuntu 12.04 image you'd use: 71 72 $ docker run -t -i ubuntu:12.04 /bin/bash 73 74 If you don't specify a variant, for example you just use `ubuntu`, then Docker 75 will default to using the `ubuntu:latest` image. 76 77 > **Tip:** 78 > You should always specify an image tag, for example `ubuntu:14.04`. 79 > That way, you always know exactly what variant of an image you are using. 80 > This is useful for troubleshooting and debugging. 81 82 ## Getting a new image 83 84 So how do you get new images? Well Docker will automatically download any image 85 you use that isn't already present on the Docker host. But this can potentially 86 add some time to the launch of a container. If you want to pre-load an image you 87 can download it using the `docker pull` command. Suppose you'd like to 88 download the `centos` image. 89 90 $ docker pull centos 91 92 Using default tag: latest 93 latest: Pulling from library/centos 94 f1b10cd84249: Pull complete 95 c852f6d61e65: Pull complete 96 7322fbe74aa5: Pull complete 97 Digest: sha256:90305c9112250c7e3746425477f1c4ef112b03b4abe78c612e092037bfecc3b7 98 Status: Downloaded newer image for centos:latest 99 100 You can see that each layer of the image has been pulled down and now you 101 can run a container from this image and you won't have to wait to 102 download the image. 103 104 $ docker run -t -i centos /bin/bash 105 106 bash-4.1# 107 108 ## Finding images 109 110 One of the features of Docker is that a lot of people have created Docker 111 images for a variety of purposes. Many of these have been uploaded to 112 [Docker Hub](https://hub.docker.com). You can search these images on the 113 [Docker Hub](https://hub.docker.com) website. 114 115  116 117 You can also search for images on the command line using the `docker search` 118 command. Suppose your team wants an image with Ruby and Sinatra installed on 119 which to do our web application development. You can search for a suitable image 120 by using the `docker search` command to find all the images that contain the 121 term `sinatra`. 122 123 $ docker search sinatra 124 NAME DESCRIPTION STARS OFFICIAL AUTOMATED 125 training/sinatra Sinatra training image 0 [OK] 126 marceldegraaf/sinatra Sinatra test app 0 127 mattwarren/docker-sinatra-demo 0 [OK] 128 luisbebop/docker-sinatra-hello-world 0 [OK] 129 bmorearty/handson-sinatra handson-ruby + Sinatra for Hands on with D... 0 130 subwiz/sinatra 0 131 bmorearty/sinatra 0 132 . . . 133 134 You can see the command returns a lot of images that use the term `sinatra`. 135 You've received a list of image names, descriptions, Stars (which measure the 136 social popularity of images - if a user likes an image then they can "star" it), 137 and the Official and Automated build statuses. [Official 138 Repositories](https://docs.docker.com/docker-hub/official_repos) are a carefully 139 curated set of Docker repositories supported by Docker, Inc. Automated 140 repositories are [Automated Builds](dockerrepos.md#automated-builds) that allow 141 you to validate the source and content of an image. 142 143 You've reviewed the images available to use and you decided to use the 144 `training/sinatra` image. So far you've seen two types of images repositories, 145 images like `ubuntu`, which are called base or root images. These base images 146 are provided by Docker Inc and are built, validated and supported. These can be 147 identified by their single word names. 148 149 You've also seen user images, for example the `training/sinatra` image you've 150 chosen. A user image belongs to a member of the Docker community and is built 151 and maintained by them. You can identify user images as they are always 152 prefixed with the user name, here `training`, of the user that created them. 153 154 ## Pulling our image 155 156 You've identified a suitable image, `training/sinatra`, and now you can download it using the `docker pull` command. 157 158 $ docker pull training/sinatra 159 160 The team can now use this image by running their own containers. 161 162 $ docker run -t -i training/sinatra /bin/bash 163 164 root@a8cb6ce02d85:/# 165 166 ## Creating our own images 167 168 The team has found the `training/sinatra` image pretty useful but it's not quite 169 what they need and you need to make some changes to it. There are two ways you 170 can update and create images. 171 172 1. You can update a container created from an image and commit the results to an image. 173 2. You can use a `Dockerfile` to specify instructions to create an image. 174 175 176 ### Updating and committing an image 177 178 To update an image you first need to create a container from the image 179 you'd like to update. 180 181 $ docker run -t -i training/sinatra /bin/bash 182 183 root@0b2616b0e5a8:/# 184 185 > **Note:** 186 > Take note of the container ID that has been created, `0b2616b0e5a8`, as you'll 187 > need it in a moment. 188 189 Inside our running container first let's update Ruby: 190 191 root@0b2616b0e5a8:/# apt-get install -y ruby2.0-dev 192 193 Now let's add the `json` gem. 194 195 root@0b2616b0e5a8:/# gem2.0 install json 196 197 Once this has completed let's exit our container using the `exit` 198 command. 199 200 Now you have a container with the change you want to make. You can then 201 commit a copy of this container to an image using the `docker commit` 202 command. 203 204 $ docker commit -m "Added json gem" -a "Kate Smith" \ 205 0b2616b0e5a8 ouruser/sinatra:v2 206 207 4f177bd27a9ff0f6dc2a830403925b5360bfe0b93d476f7fc3231110e7f71b1c 208 209 Here you've used the `docker commit` command. You've specified two flags: `-m` 210 and `-a`. The `-m` flag allows us to specify a commit message, much like you 211 would with a commit on a version control system. The `-a` flag allows us to 212 specify an author for our update. 213 214 You've also specified the container you want to create this new image from, 215 `0b2616b0e5a8` (the ID you recorded earlier) and you've specified a target for 216 the image: 217 218 ouruser/sinatra:v2 219 220 Break this target down. It consists of a new user, `ouruser`, that you're 221 writing this image to. You've also specified the name of the image, here you're 222 keeping the original image name `sinatra`. Finally you're specifying a tag for 223 the image: `v2`. 224 225 You can then look at our new `ouruser/sinatra` image using the `docker images` 226 command. 227 228 $ docker images 229 230 REPOSITORY TAG IMAGE ID CREATED SIZE 231 training/sinatra latest 5bc342fa0b91 10 hours ago 446.7 MB 232 ouruser/sinatra v2 3c59e02ddd1a 10 hours ago 446.7 MB 233 ouruser/sinatra latest 5db5f8471261 10 hours ago 446.7 MB 234 235 To use our new image to create a container you can then: 236 237 $ docker run -t -i ouruser/sinatra:v2 /bin/bash 238 239 root@78e82f680994:/# 240 241 ### Building an image from a `Dockerfile` 242 243 Using the `docker commit` command is a pretty simple way of extending an image 244 but it's a bit cumbersome and it's not easy to share a development process for 245 images amongst a team. Instead you can use a new command, `docker build`, to 246 build new images from scratch. 247 248 To do this you create a `Dockerfile` that contains a set of instructions that 249 tell Docker how to build our image. 250 251 First, create a directory and a `Dockerfile`. 252 253 $ mkdir sinatra 254 255 $ cd sinatra 256 257 $ touch Dockerfile 258 259 If you are using Docker Machine on Windows, you may access your host 260 directory by `cd` to `/c/Users/your_user_name`. 261 262 Each instruction creates a new layer of the image. Try a simple example now for 263 building your own Sinatra image for your fictitious development team. 264 265 # This is a comment 266 FROM ubuntu:14.04 267 MAINTAINER Kate Smith <ksmith@example.com> 268 RUN apt-get update && apt-get install -y ruby ruby-dev 269 RUN gem install sinatra 270 271 Examine what your `Dockerfile` does. Each instruction prefixes a statement and 272 is capitalized. 273 274 INSTRUCTION statement 275 276 > **Note:** You use `#` to indicate a comment 277 278 The first instruction `FROM` tells Docker what the source of our image is, in 279 this case you're basing our new image on an Ubuntu 14.04 image. The instruction uses the `MAINTAINER` instruction to specify who maintains the new image. 280 281 Lastly, you've specified two `RUN` instructions. A `RUN` instruction executes 282 a command inside the image, for example installing a package. Here you're 283 updating our APT cache, installing Ruby and RubyGems and then installing the 284 Sinatra gem. 285 286 287 288 Now let's take our `Dockerfile` and use the `docker build` command to build an image. 289 290 $ docker build -t ouruser/sinatra:v2 . 291 292 Sending build context to Docker daemon 2.048 kB 293 Sending build context to Docker daemon 294 Step 1 : FROM ubuntu:14.04 295 ---> e54ca5efa2e9 296 Step 2 : MAINTAINER Kate Smith <ksmith@example.com> 297 ---> Using cache 298 ---> 851baf55332b 299 Step 3 : RUN apt-get update && apt-get install -y ruby ruby-dev 300 ---> Running in 3a2558904e9b 301 Selecting previously unselected package libasan0:amd64. 302 (Reading database ... 11518 files and directories currently installed.) 303 Preparing to unpack .../libasan0_4.8.2-19ubuntu1_amd64.deb ... 304 Unpacking libasan0:amd64 (4.8.2-19ubuntu1) ... 305 Selecting previously unselected package libatomic1:amd64. 306 Preparing to unpack .../libatomic1_4.8.2-19ubuntu1_amd64.deb ... 307 Unpacking libatomic1:amd64 (4.8.2-19ubuntu1) ... 308 Selecting previously unselected package libgmp10:amd64. 309 Preparing to unpack .../libgmp10_2%3a5.1.3+dfsg-1ubuntu1_amd64.deb ... 310 Unpacking libgmp10:amd64 (2:5.1.3+dfsg-1ubuntu1) ... 311 Selecting previously unselected package libisl10:amd64. 312 Preparing to unpack .../libisl10_0.12.2-1_amd64.deb ... 313 Unpacking libisl10:amd64 (0.12.2-1) ... 314 Selecting previously unselected package libcloog-isl4:amd64. 315 Preparing to unpack .../libcloog-isl4_0.18.2-1_amd64.deb ... 316 Unpacking libcloog-isl4:amd64 (0.18.2-1) ... 317 Selecting previously unselected package libgomp1:amd64. 318 Preparing to unpack .../libgomp1_4.8.2-19ubuntu1_amd64.deb ... 319 Unpacking libgomp1:amd64 (4.8.2-19ubuntu1) ... 320 Selecting previously unselected package libitm1:amd64. 321 Preparing to unpack .../libitm1_4.8.2-19ubuntu1_amd64.deb ... 322 Unpacking libitm1:amd64 (4.8.2-19ubuntu1) ... 323 Selecting previously unselected package libmpfr4:amd64. 324 Preparing to unpack .../libmpfr4_3.1.2-1_amd64.deb ... 325 Unpacking libmpfr4:amd64 (3.1.2-1) ... 326 Selecting previously unselected package libquadmath0:amd64. 327 Preparing to unpack .../libquadmath0_4.8.2-19ubuntu1_amd64.deb ... 328 Unpacking libquadmath0:amd64 (4.8.2-19ubuntu1) ... 329 Selecting previously unselected package libtsan0:amd64. 330 Preparing to unpack .../libtsan0_4.8.2-19ubuntu1_amd64.deb ... 331 Unpacking libtsan0:amd64 (4.8.2-19ubuntu1) ... 332 Selecting previously unselected package libyaml-0-2:amd64. 333 Preparing to unpack .../libyaml-0-2_0.1.4-3ubuntu3_amd64.deb ... 334 Unpacking libyaml-0-2:amd64 (0.1.4-3ubuntu3) ... 335 Selecting previously unselected package libmpc3:amd64. 336 Preparing to unpack .../libmpc3_1.0.1-1ubuntu1_amd64.deb ... 337 Unpacking libmpc3:amd64 (1.0.1-1ubuntu1) ... 338 Selecting previously unselected package openssl. 339 Preparing to unpack .../openssl_1.0.1f-1ubuntu2.4_amd64.deb ... 340 Unpacking openssl (1.0.1f-1ubuntu2.4) ... 341 Selecting previously unselected package ca-certificates. 342 Preparing to unpack .../ca-certificates_20130906ubuntu2_all.deb ... 343 Unpacking ca-certificates (20130906ubuntu2) ... 344 Selecting previously unselected package manpages. 345 Preparing to unpack .../manpages_3.54-1ubuntu1_all.deb ... 346 Unpacking manpages (3.54-1ubuntu1) ... 347 Selecting previously unselected package binutils. 348 Preparing to unpack .../binutils_2.24-5ubuntu3_amd64.deb ... 349 Unpacking binutils (2.24-5ubuntu3) ... 350 Selecting previously unselected package cpp-4.8. 351 Preparing to unpack .../cpp-4.8_4.8.2-19ubuntu1_amd64.deb ... 352 Unpacking cpp-4.8 (4.8.2-19ubuntu1) ... 353 Selecting previously unselected package cpp. 354 Preparing to unpack .../cpp_4%3a4.8.2-1ubuntu6_amd64.deb ... 355 Unpacking cpp (4:4.8.2-1ubuntu6) ... 356 Selecting previously unselected package libgcc-4.8-dev:amd64. 357 Preparing to unpack .../libgcc-4.8-dev_4.8.2-19ubuntu1_amd64.deb ... 358 Unpacking libgcc-4.8-dev:amd64 (4.8.2-19ubuntu1) ... 359 Selecting previously unselected package gcc-4.8. 360 Preparing to unpack .../gcc-4.8_4.8.2-19ubuntu1_amd64.deb ... 361 Unpacking gcc-4.8 (4.8.2-19ubuntu1) ... 362 Selecting previously unselected package gcc. 363 Preparing to unpack .../gcc_4%3a4.8.2-1ubuntu6_amd64.deb ... 364 Unpacking gcc (4:4.8.2-1ubuntu6) ... 365 Selecting previously unselected package libc-dev-bin. 366 Preparing to unpack .../libc-dev-bin_2.19-0ubuntu6_amd64.deb ... 367 Unpacking libc-dev-bin (2.19-0ubuntu6) ... 368 Selecting previously unselected package linux-libc-dev:amd64. 369 Preparing to unpack .../linux-libc-dev_3.13.0-30.55_amd64.deb ... 370 Unpacking linux-libc-dev:amd64 (3.13.0-30.55) ... 371 Selecting previously unselected package libc6-dev:amd64. 372 Preparing to unpack .../libc6-dev_2.19-0ubuntu6_amd64.deb ... 373 Unpacking libc6-dev:amd64 (2.19-0ubuntu6) ... 374 Selecting previously unselected package ruby. 375 Preparing to unpack .../ruby_1%3a1.9.3.4_all.deb ... 376 Unpacking ruby (1:1.9.3.4) ... 377 Selecting previously unselected package ruby1.9.1. 378 Preparing to unpack .../ruby1.9.1_1.9.3.484-2ubuntu1_amd64.deb ... 379 Unpacking ruby1.9.1 (1.9.3.484-2ubuntu1) ... 380 Selecting previously unselected package libruby1.9.1. 381 Preparing to unpack .../libruby1.9.1_1.9.3.484-2ubuntu1_amd64.deb ... 382 Unpacking libruby1.9.1 (1.9.3.484-2ubuntu1) ... 383 Selecting previously unselected package manpages-dev. 384 Preparing to unpack .../manpages-dev_3.54-1ubuntu1_all.deb ... 385 Unpacking manpages-dev (3.54-1ubuntu1) ... 386 Selecting previously unselected package ruby1.9.1-dev. 387 Preparing to unpack .../ruby1.9.1-dev_1.9.3.484-2ubuntu1_amd64.deb ... 388 Unpacking ruby1.9.1-dev (1.9.3.484-2ubuntu1) ... 389 Selecting previously unselected package ruby-dev. 390 Preparing to unpack .../ruby-dev_1%3a1.9.3.4_all.deb ... 391 Unpacking ruby-dev (1:1.9.3.4) ... 392 Setting up libasan0:amd64 (4.8.2-19ubuntu1) ... 393 Setting up libatomic1:amd64 (4.8.2-19ubuntu1) ... 394 Setting up libgmp10:amd64 (2:5.1.3+dfsg-1ubuntu1) ... 395 Setting up libisl10:amd64 (0.12.2-1) ... 396 Setting up libcloog-isl4:amd64 (0.18.2-1) ... 397 Setting up libgomp1:amd64 (4.8.2-19ubuntu1) ... 398 Setting up libitm1:amd64 (4.8.2-19ubuntu1) ... 399 Setting up libmpfr4:amd64 (3.1.2-1) ... 400 Setting up libquadmath0:amd64 (4.8.2-19ubuntu1) ... 401 Setting up libtsan0:amd64 (4.8.2-19ubuntu1) ... 402 Setting up libyaml-0-2:amd64 (0.1.4-3ubuntu3) ... 403 Setting up libmpc3:amd64 (1.0.1-1ubuntu1) ... 404 Setting up openssl (1.0.1f-1ubuntu2.4) ... 405 Setting up ca-certificates (20130906ubuntu2) ... 406 debconf: unable to initialize frontend: Dialog 407 debconf: (TERM is not set, so the dialog frontend is not usable.) 408 debconf: falling back to frontend: Readline 409 debconf: unable to initialize frontend: Readline 410 debconf: (This frontend requires a controlling tty.) 411 debconf: falling back to frontend: Teletype 412 Setting up manpages (3.54-1ubuntu1) ... 413 Setting up binutils (2.24-5ubuntu3) ... 414 Setting up cpp-4.8 (4.8.2-19ubuntu1) ... 415 Setting up cpp (4:4.8.2-1ubuntu6) ... 416 Setting up libgcc-4.8-dev:amd64 (4.8.2-19ubuntu1) ... 417 Setting up gcc-4.8 (4.8.2-19ubuntu1) ... 418 Setting up gcc (4:4.8.2-1ubuntu6) ... 419 Setting up libc-dev-bin (2.19-0ubuntu6) ... 420 Setting up linux-libc-dev:amd64 (3.13.0-30.55) ... 421 Setting up libc6-dev:amd64 (2.19-0ubuntu6) ... 422 Setting up manpages-dev (3.54-1ubuntu1) ... 423 Setting up libruby1.9.1 (1.9.3.484-2ubuntu1) ... 424 Setting up ruby1.9.1-dev (1.9.3.484-2ubuntu1) ... 425 Setting up ruby-dev (1:1.9.3.4) ... 426 Setting up ruby (1:1.9.3.4) ... 427 Setting up ruby1.9.1 (1.9.3.484-2ubuntu1) ... 428 Processing triggers for libc-bin (2.19-0ubuntu6) ... 429 Processing triggers for ca-certificates (20130906ubuntu2) ... 430 Updating certificates in /etc/ssl/certs... 164 added, 0 removed; done. 431 Running hooks in /etc/ca-certificates/update.d....done. 432 ---> c55c31703134 433 Removing intermediate container 3a2558904e9b 434 Step 4 : RUN gem install sinatra 435 ---> Running in 6b81cb6313e5 436 unable to convert "\xC3" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to US-ASCII for README.rdoc, skipping 437 unable to convert "\xC3" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to US-ASCII for README.rdoc, skipping 438 Successfully installed rack-1.5.2 439 Successfully installed tilt-1.4.1 440 Successfully installed rack-protection-1.5.3 441 Successfully installed sinatra-1.4.5 442 4 gems installed 443 Installing ri documentation for rack-1.5.2... 444 Installing ri documentation for tilt-1.4.1... 445 Installing ri documentation for rack-protection-1.5.3... 446 Installing ri documentation for sinatra-1.4.5... 447 Installing RDoc documentation for rack-1.5.2... 448 Installing RDoc documentation for tilt-1.4.1... 449 Installing RDoc documentation for rack-protection-1.5.3... 450 Installing RDoc documentation for sinatra-1.4.5... 451 ---> 97feabe5d2ed 452 Removing intermediate container 6b81cb6313e5 453 Successfully built 97feabe5d2ed 454 455 You've specified our `docker build` command and used the `-t` flag to identify 456 our new image as belonging to the user `ouruser`, the repository name `sinatra` 457 and given it the tag `v2`. 458 459 You've also specified the location of our `Dockerfile` using the `.` to 460 indicate a `Dockerfile` in the current directory. 461 462 > **Note:** 463 > You can also specify a path to a `Dockerfile`. 464 465 Now you can see the build process at work. The first thing Docker does is 466 upload the build context: basically the contents of the directory you're 467 building in. This is done because the Docker daemon does the actual 468 build of the image and it needs the local context to do it. 469 470 Next you can see each instruction in the `Dockerfile` being executed 471 step-by-step. You can see that each step creates a new container, runs 472 the instruction inside that container and then commits that change - 473 just like the `docker commit` work flow you saw earlier. When all the 474 instructions have executed you're left with the `97feabe5d2ed` image 475 (also helpfuly tagged as `ouruser/sinatra:v2`) and all intermediate 476 containers will get removed to clean things up. 477 478 > **Note:** 479 > An image can't have more than 127 layers regardless of the storage driver. 480 > This limitation is set globally to encourage optimization of the overall 481 > size of images. 482 483 You can then create a container from our new image. 484 485 $ docker run -t -i ouruser/sinatra:v2 /bin/bash 486 487 root@8196968dac35:/# 488 489 > **Note:** 490 > This is just a brief introduction to creating images. We've 491 > skipped a whole bunch of other instructions that you can use. We'll see more of 492 > those instructions in later sections of the Guide or you can refer to the 493 > [`Dockerfile`](../reference/builder.md) reference for a 494 > detailed description and examples of every instruction. 495 > To help you write a clear, readable, maintainable `Dockerfile`, we've also 496 > written a [`Dockerfile` Best Practices guide](../userguide/eng-image/dockerfile_best-practices.md). 497 498 499 ## Setting tags on an image 500 501 You can also add a tag to an existing image after you commit or build it. We 502 can do this using the `docker tag` command. Now, add a new tag to your 503 `ouruser/sinatra` image. 504 505 $ docker tag 5db5f8471261 ouruser/sinatra:devel 506 507 The `docker tag` command takes the ID of the image, here `5db5f8471261`, and our 508 user name, the repository name and the new tag. 509 510 Now, see your new tag using the `docker images` command. 511 512 $ docker images ouruser/sinatra 513 514 REPOSITORY TAG IMAGE ID CREATED SIZE 515 ouruser/sinatra latest 5db5f8471261 11 hours ago 446.7 MB 516 ouruser/sinatra devel 5db5f8471261 11 hours ago 446.7 MB 517 ouruser/sinatra v2 5db5f8471261 11 hours ago 446.7 MB 518 519 ## Image Digests 520 521 Images that use the v2 or later format have a content-addressable identifier 522 called a `digest`. As long as the input used to generate the image is 523 unchanged, the digest value is predictable. To list image digest values, use 524 the `--digests` flag: 525 526 $ docker images --digests | head 527 528 REPOSITORY TAG DIGEST IMAGE ID CREATED SIZE 529 ouruser/sinatra latest sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf 5db5f8471261 11 hours ago 446.7 MB 530 531 When pushing or pulling to a 2.0 registry, the `push` or `pull` command 532 output includes the image digest. You can `pull` using a digest value. 533 534 $ docker pull ouruser/sinatra@sha256:cbbf2f9a99b47fc460d422812b6a5adff7dfee951d8fa2e4a98caa0382cfbdbf 535 536 You can also reference by digest in `create`, `run`, and `rmi` commands, as well as the 537 `FROM` image reference in a Dockerfile. 538 539 ## Push an image to Docker Hub 540 541 Once you've built or created a new image you can push it to [Docker 542 Hub](https://hub.docker.com) using the `docker push` command. This 543 allows you to share it with others, either publicly, or push it into [a 544 private repository](https://hub.docker.com/account/billing-plans/). 545 546 $ docker push ouruser/sinatra 547 548 The push refers to a repository [ouruser/sinatra] (len: 1) 549 Sending image list 550 Pushing repository ouruser/sinatra (3 tags) 551 . . . 552 553 ## Remove an image from the host 554 555 You can also remove images on your Docker host in a way [similar to 556 containers](usingdocker.md) using the `docker rmi` command. 557 558 Delete the `training/sinatra` image as you don't need it anymore. 559 560 $ docker rmi training/sinatra 561 562 Untagged: training/sinatra:latest 563 Deleted: 5bc342fa0b91cabf65246837015197eecfa24b2213ed6a51a8974ae250fedd8d 564 Deleted: ed0fffdcdae5eb2c3a55549857a8be7fc8bc4241fb19ad714364cbfd7a56b22f 565 Deleted: 5c58979d73ae448df5af1d8142436d81116187a7633082650549c52c3a2418f0 566 567 > **Note:** To remove an image from the host, please make sure 568 > that there are no containers actively based on it. 569 570 # Next steps 571 572 Until now you've seen how to build individual applications inside Docker 573 containers. Now learn how to build whole application stacks with Docker 574 by networking together multiple Docker containers. 575 576 Go to [Network containers](networkingcontainers.md).