滚滚向前滚

导航

 

目录

一、第一个Docker容器

        使用docker run 命令时,如果在本地没有改镜像,那么会直接重Docker Hub(一个官方的镜像库)中拉取镜像。

docker run --rm hello-world

# 运行结果展示
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pulling fs layer 
docker: error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/registry-v2/docker/registry/v2/blobs/sha256/e3/e38bc07ac18ee64e6d59cf2eafcdddf9cec2364dfe129fe0af75f1b0194e0c96/data?Expires=1525996669&Signature=M6vcU5NqAiIMXSuJowD1zmLStFXMGck436eqPJk6GdSKrx4v~YIkV1DHQpz5aKOQnPIHowmSe6wLPWCn7E4U2my-BNqhbRVr65ndw-fJYO0eucaeRnEp7jkyhfxNJFWzMiVHmk~U595HGt4vZ4E50Umc76xKLvciYl1HGLwJhtw_&Key-Pair-Id=APKAJECH5M7VWIS5YZ6Q: net/http: TLS handshake timeout.
See 'docker run --help'.
[gupan@localhost ~]$ docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete 
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

二、第一个Docker镜像

2.1 创建Docker镜像准备工作

# 新建一个文件夹hello
mkdir hello
cd hello
# hello中新建一个文件,命名为Dockerfile,文件内容如下:
FROM alpine # 即将构建的镜像是基于名为Apline的镜像
CMD "echo" "Hello World"

2.2 构建Docker镜像

打包镜像

# 将上面的文件打包
docker build -t hello .
# -t 后面的参数是给这个镜像取得标签,.代表重当前路径搜索Dockerfile文件,并执行里面的代码

运行结果

[gupan@localhost hello]$ docker build -t hello .
Sending build context to Docker daemon  2.048kB
Step 1/2 : FROM alpine
latest: Pulling from library/alpine
ff3a5c916c92: Pull complete 
Digest: sha256:7df6db5aa61ae9480f52f0b3a06a140ab98d427f86d8d5de0bedab9b8df6b1c0
Status: Downloaded newer image for alpine:latest
 ---> 3fd9065eaf02
Step 2/2 : CMD "echo" "Hello World"
 ---> Running in 4891b2d2a317
Removing intermediate container 4891b2d2a317
 ---> 4b1c2e073c23
Successfully built 4b1c2e073c23
Successfully tagged hello:latest

执行镜像

[gupan@localhost hello]$ docker run --rm hello
Hello World
[gupan@localhost hello]$ 
posted on 2018-05-10 20:36  滚滚向前滚  阅读(264)  评论(0编辑  收藏  举报