04 分享应用镜像

分享docker镜像

既然我们已经创建了一个镜像,我们就可以分享我们的Docker镜像,这需要使用到Docker registry. 默认的registry是Docker Hub,这也是我们前面使用到的镜像的来源。

Docker id是到hub.docker.com注册并创建的账号(docker registry私服是另外的情况)

创建仓库

To push an image, we first need to create a repository on Docker Hub.

  1. Sign up or sign in to Docker Hub.
  2. Click the Create Repository button.
  3. For the repo name, use getting-started. Make sure the visibility is public.
  4. Click the create button.

推送镜像到仓库

  1. 在命令行,运行如下push命令:

    docker push w784319947/getting-started

    这里,我的Docker Hub账号是w784319947,我在Docker Hub中创建了getting-started仓库。而我本地也存在待推送到仓库的getting-started镜像。

    但是这里会失败。需要本地登录docker账户,同时本地镜像名需要加<docker账号>/前缀。

  2. 命令行登录到Docker Hub

    docker login -u w784319947
  3. 修改镜像名前缀(重新打tag)

    docker tag getting-started w784319947/getting-started
  4. 重新推送到Docker Hub远程仓库

    docker push w784319947/getting-started

    这次推送成功了。浏览器打开http://hub.docker.com,并登录。确实发现仓库中已经有个相应的镜像了。前面我们只是修改了镜像名,没有加tag到镜像名后。这种情况:If you don’t specify a tag, Docker will use a tag called latest.

    而且发现,不提前在Docker Hub建同名仓库,直接推送也可以的。

在一个新实例中运行镜像

我们创建了应用的镜像,并将其推送到了一个registry(Docker Hub)。

我们现在就可以在任意一个连通互联网的装有docker的主机上,运行此应用的全新的镜像实例(容器)了。

  1. Open your browser to Play with Docker.

  2. Click Login and then select docker from the drop-down list.

  3. Connect with your Docker Hub account.

  4. Once you’re logged in, click on the ADD NEW INSTANCE option on the left side bar. If you don’t see it, make your browser a little wider. After a few seconds, a terminal window opens in your browser.

  5. In the terminal, start your freshly pushed app.

     $ docker run -dp 3000:3000 YOUR-USER-NAME/getting-started

    You should see the image get pulled down and eventually start up!

  6. Click on the 3000 badge when it comes up and you should see the app with your modifications! Hooray! If the 3000 badge doesn’t show up, you can click on the “Open Port” button and type in 3000.


评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注