Skip to content

永远的HelloWorld

1. 测试运行(hello-world)

sh
[jack@hadoop102 ~]$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Head "https://registry-1.docker.io/v2/library/hello-world/manifests/latest": dial tcp [2600:1f18:2148:bc00:8d61:9b62:40aa:8bb8]:443: connect: network is unreachable.
See 'docker run --help'.

hello-world镜像在本地不存在,执行run命令会自动远程从Docker仓库中拉取后运行镜像。此时报错是因为找不到registry-1.docker.io的DNS信息,原因是DNS解析域名出现了问题,需要设置海外的DNS服务器,如谷歌DNS8.8.8.8。

2. 配置域名解析

特别是服务器是安装在虚拟机上的,默认第一DNS服务器地址是本地宿主机,本地宿主机不具备DNS解析功能,以下就是设置常用的DNS,其中谷歌DNS有8.8.8.8和8.8.4.4, 设置一个就足够了,另外114.114.114.114是国内DNS服务器地址,防止国内地址访问不了。

sh
[jack@hadoop102 ~]$ sudo vi /etc/resolv.conf
# 删除第一行内容
nameserver 192.168.101.1
# 添加以下内容
nameserver 8.8.8.8
nameserver 114.114.114.114

3. 重新拉取镜像

sh
[jack@hadoop102 ~]$ sudo docker pull hello-world
Using default tag: latest
latest: Pulling from library/hello-world
c1ec31eb5944: Pull complete 
Digest: sha256:a26bff933ddc26d5cdf7faa98b4ae1e3ec20c4985e6f87ac0973052224d24302
Status: Downloaded newer image for hello-world:latest
docker.io/library/hello-world:latest
[jack@hadoop102 ~]$ sudo docker run hello-world

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/get-started/

6. run命令执行逻辑

Alt text