@@ -12,147 +12,149 @@ redirect_from:
12
12
title : Tag, push, and pull your image
13
13
---
14
14
15
- In this section, you tag and push your ` docker-whale ` image to your newly
16
- created repository. When you are done, you test the repository by pulling your
15
+ In this section, you tag and push your ` docker-whale ` image to your new
16
+ repository, then test the repository by pulling your
17
17
new image.
18
18
19
19
## Step 1: Tag and push the image
20
20
21
- If you don't already have a terminal open, open one now:
21
+ 1 . If you don't already have a terminal open, open one now.
22
22
23
- 1 . Go back to your command line terminal.
23
+ 2 . Run ` docker images ` to list the images stored locally:
24
24
25
- 2 . At the prompt, type ` docker images ` to list the images you currently have:
25
+ ``` bash
26
+ $ docker images
27
+
28
+ REPOSITORY TAG IMAGE ID CREATED SIZE
29
+ docker-whale latest 7d9495d03763 38 minutes ago 273.7 MB
30
+ < none> < none> 5dac217f722c 45 minutes ago 273.7 MB
31
+ docker/whalesay latest fb434121fc77 4 hours ago 247 MB
32
+ hello-world latest 91c95931e552 5 weeks ago 910 B
33
+ ```
34
+
35
+ 5. Find the image ID for the `docker-whale` image, in the second column. In this example,
36
+ the id is ` 7d9495d03763` , but yours will be different.
26
37
27
- $ docker images
28
- REPOSITORY TAG IMAGE ID CREATED SIZE
29
- docker-whale latest 7d9495d03763 38 minutes ago 273.7 MB
30
- <none> <none> 5dac217f722c 45 minutes ago 273.7 MB
31
- docker/whalesay latest fb434121fc77 4 hours ago 247 MB
32
- hello-world latest 91c95931e552 5 weeks ago 910 B
38
+ > ** Note** : Currently, the repository shows the repo name ` docker-whale`
39
+ > with no namespace. You need to include the ` namespace` for Docker Hub to
40
+ > associate it with your account. The ` namespace` is the same as your Docker
41
+ > Hub account name. The next step adds the namespace to the image name, like
42
+ > ` YOUR_DOCKERHUB_NAME/docker-whale` .
33
43
34
- 5 . Find the ` IMAGE ID ` for your ` docker-whale ` image.
35
-
36
- In this example, the id is ` 7d9495d03763 ` .
37
-
38
- Notice that currently, the ` REPOSITORY ` shows the repo name ` docker-whale `
39
- but not the namespace. You need to include the ` namespace ` for Docker Hub to
40
- associate it with your account. The ` namespace ` is the same as your Docker
41
- Hub account name. You need to rename the image to
42
- ` YOUR_DOCKERHUB_NAME/docker-whale ` .
43
-
44
- 6 . Use ` IMAGE ID ` and the ` docker tag ` command to tag your ` docker-whale ` image.
44
+ 6. Tag the ` docker-whale` image using the ` docker tag` command and the image ID.
45
45
46
46
The command you type looks like this:
47
47
48
48
! [Docker tag command](tutimg/tagger.png)
49
49
50
- Of course, your account name will be your own. So, you type the command with
51
- your image's ID and your account name and press RETURN.
52
-
53
- $ docker tag 7d9495d03763 maryatdocker/docker-whale:latest
54
-
55
- 7 . Type the ` docker images ` command again to see your newly tagged image.
56
-
57
- $ docker images
58
- REPOSITORY TAG IMAGE ID CREATED SIZE
59
- maryatdocker/docker-whale latest 7d9495d03763 5 minutes ago 273.7 MB
60
- docker-whale latest 7d9495d03763 2 hours ago 273.7 MB
61
- <none> <none> 5dac217f722c 5 hours ago 273.7 MB
62
- docker/whalesay latest fb434121fc77 5 hours ago 247 MB
63
- hello-world latest 91c95931e552 5 weeks ago 910 B
64
-
65
- 8 . Use the ` docker login ` command to log into the Docker Hub from the command line.
50
+ Make sure to use your own Docker Hub account name.
51
+
52
+ ` ` ` bash
53
+ $ docker tag 7d9495d03763 maryatdocker/docker-whale:latest
54
+ ` ` `
55
+
56
+ 7. Run ` docker images` again to verify that the ` docker-whale` image has been tagged.
57
+
58
+ ` ` ` bash
59
+ $ docker images
60
+
61
+ REPOSITORY TAG IMAGE ID CREATED SIZE
62
+ maryatdocker/docker-whale latest 7d9495d03763 5 minutes ago 273.7 MB
63
+ docker-whale latest 7d9495d03763 2 hours ago 273.7 MB
64
+ < none> < none> 5dac217f722c 5 hours ago 273.7 MB
65
+ docker/whalesay latest fb434121fc77 5 hours ago 247 MB
66
+ hello-world latest 91c95931e552 5 weeks ago 910 B
67
+ ` ` `
68
+
69
+ The same image ID actually now exists in two different repositories.
70
+
71
+ 8. Before you can push the image to Docker Hub, you need to log in, using
72
+ the ` docker login` command. The command doesn' t take any parameters,
73
+ but prompts you for the username and password, as below:
74
+
75
+ ```bash
76
+ $ docker login
77
+
78
+ Username: *****
79
+ Password: *****
80
+ Login Succeeded
81
+ ```
66
82
67
- The format for the login command is:
83
+ 9. Push your tagged image to Docker Hub, using the `docker push` command. A
84
+ lot of output is generated, as each layer is pushed separately. That
85
+ output is truncated in the example below.
68
86
69
- docker login
87
+ ```bash
88
+ $ docker push maryatdocker/docker-whale
89
+
90
+ The push refers to a repository [maryatdocker/docker-whale] (len: 1)
91
+ 7d9495d03763: Image already exists
92
+ ...
93
+ e9e06b06e14c: Image successfully pushed
94
+ Digest: sha256:ad89e88beb7dc73bf55d456e2c600e0a39dd6c9500d7cd8d1025626c4b985011
95
+ ```
70
96
71
- When prompted, enter your password and press enter. So, for example:
97
+ 10. Go back to the Docker Hub website to see the newly-pushed image.
72
98
73
- $ docker login
74
- Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
75
- Username:
76
- Password:
77
- Login Succeeded
78
-
79
- 9 . Type the ` docker push ` command to push your image to your new repository.
80
-
81
- $ docker push maryatdocker/docker-whale
82
- The push refers to a repository [maryatdocker/docker-whale] (len: 1)
83
- 7d9495d03763: Image already exists
84
- c81071adeeb5: Image successfully pushed
85
- eb06e47a01d2: Image successfully pushed
86
- fb434121fc77: Image successfully pushed
87
- 5d5bd9951e26: Image successfully pushed
88
- 99da72cfe067: Image successfully pushed
89
- 1722f41ddcb5: Image successfully pushed
90
- 5b74edbcaa5b: Image successfully pushed
91
- 676c4a1897e6: Image successfully pushed
92
- 07f8e8c5e660: Image successfully pushed
93
- 37bea4ee0c81: Image successfully pushed
94
- a82efea989f9: Image successfully pushed
95
- e9e06b06e14c: Image successfully pushed
96
- Digest: sha256:ad89e88beb7dc73bf55d456e2c600e0a39dd6c9500d7cd8d1025626c4b985011
97
-
98
- 10 . Return to your profile on Docker Hub to see your new image.
99
-
100
- ![ Docker tag command] ( tutimg/new_image.png )
99
+ 
100
+
101
101
102
102
## Step 2: Pull your new image
103
103
104
- In this last section, you'll pull the image you just pushed to hub. Before you
105
- do that though, you'll need to remove the original image from your local
106
- machine. If you left the original image on your machine, Docker would not pull
107
- from the hub &mdash ; why would it? The two images are identical.
104
+ The goal of pushing the image to Docker Hub is so that you can access
105
+ it from any Docker host using `docker pull`. First, though, you need to
106
+ remove the local copy. Otherwise, `docker pull` will not have any work to do,
107
+ because it will see that you already have the latest version of the image
108
+ locally.
108
109
109
- 1 . Make sure Docker is running, and open a command line terminal .
110
+ 1. If you don ' t already have a terminal open, open one now .
110
111
111
- 2 . At the prompt, type ` docker images ` to list the images you currently have on your local machine .
112
+ 2. Use ` docker images` to list the images you have locally .
112
113
114
+ ` ` ` bash
113
115
$ docker images
116
+
114
117
REPOSITORY TAG IMAGE ID CREATED SIZE
115
118
maryatdocker/docker-whale latest 7d9495d03763 5 minutes ago 273.7 MB
116
119
docker-whale latest 7d9495d03763 2 hours ago 273.7 MB
117
120
< none> < none> 5dac217f722c 5 hours ago 273.7 MB
118
121
docker/whalesay latest fb434121fc77 5 hours ago 247 MB
119
122
hello-world latest 91c95931e552 5 weeks ago 910 B
120
-
121
- To make a good test, you need to remove the `maryatdocker/docker-whale` and
122
- ` docker-whale ` images from your local system. Removing them forces the next
123
- ` docker pull ` to get the image from your repository.
124
-
125
- 3 . Use the ` docker rmi ` to remove the ` maryatdocker/docker-whale ` and ` docker-whale `
126
- images.
127
-
128
- You can use an ID or the name to remove an image.
129
-
130
- $ docker rmi -f 7d9495d03763
131
- $ docker rmi -f docker-whale
132
-
133
- 4 . Pull and load a new image from your repository using the ` docker run ` command.
134
-
135
- The command you type should include your username from Docker Hub.
136
-
137
- docker run yourusername/docker-whale
138
-
139
- Since the image is no longer available on your local system, Docker downloads it.
140
-
123
+ ` ` `
124
+
125
+ In the next step, you will remove both versions of the ` docker-whale` image
126
+ from your local system. They share the same ID. Make a note of it.
127
+
128
+ 3. Use the ` docker image remove` command to remove the images. You can refer
129
+ to an image by its ID or its name. Since they share an ID, if you wanted to
130
+ keep one of them, you' d need to refer to the other one by name. For this
131
+ example, use the ID to remove both of them. Your ID will be different from
132
+ the one below.
133
+
134
+ ```bash
135
+ $ docker image remove 7d9495d03763
136
+ ```
137
+
138
+ 4. When you use `docker run` it automatically downloads (pulls) images that
139
+ don' t yet exist locally, creates a container, and starts it. Use the
140
+ following command to pull and run the ` docker-whale` image, substituting
141
+ your Docker Hub username.
142
+
143
+ ` ` ` bash
144
+ $ docker run yourusername/docker-whale
145
+ ` ` `
146
+
147
+ Since the image is no longer available on your local system, Docker
148
+ downloads it. The output below is truncated.
149
+
150
+ ` ` ` bash
141
151
$ docker run maryatdocker/docker-whale
152
+
142
153
Unable to find image ' maryatdocker/docker-whale:latest' locally
143
154
latest: Pulling from maryatdocker/docker-whale
144
155
eb06e47a01d2: Pull complete
145
156
c81071adeeb5: Pull complete
146
- 7d9495d03763: Already exists
147
- e9e06b06e14c: Already exists
148
- a82efea989f9: Already exists
149
- 37bea4ee0c81: Already exists
150
- 07f8e8c5e660: Already exists
151
- 676c4a1897e6: Already exists
152
- 5b74edbcaa5b: Already exists
153
- 1722f41ddcb5: Already exists
154
- 99da72cfe067: Already exists
155
- 5d5bd9951e26: Already exists
157
+ ...
156
158
fb434121fc77: Already exists
157
159
Digest: sha256:ad89e88beb7dc73bf55d456e2c600e0a39dd6c9500d7cd8d1025626c4b985011
158
160
Status: Downloaded newer image for maryatdocker/docker-whale:latest
@@ -178,23 +180,24 @@ images.
178
180
\_ _____ o __/
179
181
\ \ __/
180
182
\_ ___\_ _____/
183
+ ` ` `
181
184
182
- ## Where to go next
185
+ # # Next steps
183
186
184
- You've done a lot, you've done all of the following fundamental Docker tasks.
187
+ After finishing this tutorial, you' ve done all of the following fundamental
188
+ Docker tasks.
185
189
186
- * installed Docker
187
- * run a software image in a container
188
- * located an interesting image on Docker Hub
189
- * run the image on your own machine
190
- * modified an image to create your own and run it
191
- * created a Docker Hub account and repository
192
- * pushed your image to Docker Hub for others to share
190
+ * You installed Docker.
191
+ * You ran a software image in a container.
192
+ * You located an interesting image on Docker Hub and ran it on your own machine.
193
+ * You modified an image to create your own, and created and ran a container
194
+ based on that image.
195
+ * You created a Docker Hub account and repository.
196
+ * You pushed your custom image to Docker Hub, and made it available both for
197
+ yourself and other Docker users.
193
198
194
199
<a href="https://twitter.com/intent/tweet?button_hashtag=dockerdocs&text=Just%20ran%20a%20container%20with%20an%20image%20I%20built.%20Find%20it%20on%20%23dockerhub.%20Build%20your%20own%3A%20http%3A%2F%2Fgoo.gl%2FMUi7cA" class="twitter-hashtag-button" data-size="large" data-related="docker" target="_blank">Tweet your accomplishment!</a>
195
200
<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?' http' :' https' ;if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+' ://platform.twitter.com/widgets.js' ;fjs.parentNode.insertBefore(js,fjs);}}(document, ' script' , ' twitter-wjs' );</script>
196
201
197
- You've only scratched the surface of what Docker can do. Go to the next page to [ learn more] ( last_page.md ) .
198
-
199
-
200
-   ;
202
+ You' ve only scratched the surface of what Docker can do.
203
+ [Learn more](last_page.md) about where to go next.
0 commit comments