Docker部署及运行首个image --hello-world示例

今天首次开始接触Docker并开始尝试的部署Docker,这里对部署及运行过程进行总结。

首先会发现Linux无法连接外网的问题,这里可以参考:

http://www.cnblogs.com/jasmine-Jobs/p/5928218.html

来进行设置桥接模式上外网。

下面开始进入正题

1.Docker的部署:

    Docker可以在windows下Linux下及macOS下进行部署,主要是参考如下链接:

   http://www.runoob.com/docker/centos-docker-install.html

    该链接下的部署相对来说是最简洁和便捷的。其他的部署方式需要自己一步一步的进行下载及更新,对于小白来说,该方法适合首次开始部署,

runoob@runoob:~$ wget -qO- https://get.docker.com/ | sh

只需要一行命令 即可开始自动下载及执行,由于Linux中现在已经开始自带了Docker,所以其实这里的部署只是个更新的过程,

2. 开始运行Docker的 hello-world

    2.1 遇到的问题:

Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled while waiting for connection (Client.Timeout exceeded while awaiting headers).
See 'docker run --help'. 

   该问题出现的原因无解,其实就是因为在Linux的terminal中无法联网导致的,这样的问题也会出现在诸如Gradle、maven中,我们需要进行代理的配置:

    配置代理的方法:

       1.使用root权限 创建docker.service.d目录

$ mkdir -p /etc/systemd/system/docker.service.d

     2.创建HTTP或者HTTPS代理文件

           创建文件的Linux命令如下:

touch 文件名
vim /etc/systemd/system/docker.service.d/http-proxy.conf


或者:

vim /etc/systemd/system/docker.service.d/https-proxy.conf

  3.修改https-proxy.config文件

[Service]
Environment="HTTPS_PROXY=xxx.xxx.xxx.xxx:443" "NO_PROXY=localhost,127.0.0.1,xxx.xxxxxx:5000"



或者:
Environment="HTTP_PROXY=http://172.18.208.233:8080/"

   修改文件的Linux中 需要使用sudo vim XXXX命令

   其中vim的操作解释可参考:https://blog.csdn.net/u013485792/article/details/50607196

创建完后  我们需要对Docker进行重载,重载的命令如下:

 

sudo systemctl daemon-reload

  然后对Docker进行重启:

   sudo systemctl restart docker

这里我在重启的时候 会报错:
 

Unable to find image 'hello-world:latest' locally
docker: Error response from daemon: Get https://registry-1.docker.io/v2/: proxyconnect tcp: dial tcp 172.17.202.233:8080: 

connect: no route to host

原因大概是防火墙的阻挡吧  需要使用命令 sudo iptables -F  对防火墙进行清除操作,

然后重启Linux哦,重启Linux哦 不然还是会报错,我重启后就不报这个错了

开始运行image吧:
 

root@ubuntu:/home/huangjia# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete 
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
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/get-started/

好啦 要是看到上面的示例  那就说明 你的Docker部署及运行成功了

 

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值