文档章节

Mac Docker安装流程

writeademo
 writeademo
发布于 08/18 22:07
字数 1313
阅读 6
收藏 0

久仰Docker大名已久,于是今天趁着有空,尝试了一下Docker 
先是从docker的官网上下载下来mac版本的docker安装包,安装很简易,就直接拖图标就好了。

 

https://www.docker.com/products/docker-desktop

 

按照官网教程,输入了:

$ docker run hello-world
  •  

输入了好多次总是出错。

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b04784fba78d: Pulling fs layer 
docker: error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/registry-v2/docker/registry/v2/blobs/sha256/18/1815c82652c03bfd8644afda26fb184f2ed891d921b20a0703b46768f9755c57/data?Expires=1504854289&Signature=Sq~Ruv4S51ePsuXxIXTDZ8PFESR5Eu6bqmPyYjcQPeplwqOVZxsaF8W3tsIqMMebNz0hZ1jJWN7LoSWF9pPbhIlwOfuKkT92JvbDN30DvftzisY5dYuw3BKmrqiv67QmWRYIsFdGiQxb2rWE0quUiSvKAWs5pfF6dhbXRtVrAxA_&Key-Pair-Id=APKAJECH5M7VWIS5YZ6Q: dial tcp: lookup dseasb33srnrn.cloudfront.net on 192.168.65.1:53: read udp 192.168.65.2:54463->192.168.65.1:53: i/o timeout.
See 'docker run --help'.

于是查看了stackoverlow,发现是proxy的问题,哦,就是我开了vpn呗,于是就把蓝灯的vpn关了,再输入一次,依旧不行。这时候再看,发现要重启docker。于是重启之后,果然当当当安装好了。

 docker-image-files docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b04784fba78d: Pull complete 
Digest: sha256:f3b3b28a45160805bb16542c9531888519430e9e6d6ffc09d72261b0d26ff74f
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.
 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://cloud.docker.com/

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

创建APP

接着需要装docker上的环境了,于是新建一个文件夹Docker-Image, 然后再在这个文件夹里面vim Dockerfile,新建一个文件,复制粘贴以下内容:

# Use an official Python runtime as a parent image
FROM python:2.7-slim

# Set the working directory to /app
WORKDIR /app

# Copy the current directory contents into the container at /app
ADD . /app

# Install any needed packages specified in requirements.txt
RUN pip install -r requirements.txt

# Make port 80 available to the world outside this container
EXPOSE 80

# Define environment variable
ENV NAME World

# Run app.py when the container launches
CMD ["python", "app.py"]

接着同一目录下,创建两个文件requirements.txt 以及 app.py

requirements.txt

Flask
Redis

app.py

from flask import Flask
from redis import Redis, RedisError
import os
import socket

# Connect to Redis
redis = Redis(host="redis", db=0, socket_connect_timeout=2, socket_timeout=2)

app = Flask(__name__)

@app.route("/")
def hello():
    try:
        visits = redis.incr("counter")
    except RedisError:
        visits = "<i>cannot connect to Redis, counter disabled</i>"

    html = "<h3>Hello {name}!</h3>" \
           "<b>Hostname:</b> {hostname}<br/>" \
           "<b>Visits:</b> {visits}"
    return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname(), visits=visits)

if __name__ == "__main__":
    app.run(host='0.0.0.0', port=80)

接着确保自己在当前目录Docker-Image下:

$ ls
Dockerfile      app.py          requirements.txt

开始创建docker的app,不要忘记最后的那个点

$ docker build -t friendlyhello .

如果创建成功的话,会在你当前的目录下

$ docker images

REPOSITORY            TAG                 IMAGE ID
friendlyhello         latest              326387cea398

然额我肯定又失败了:

Sending build context to Docker daemon  4.608kB
Step 1/7 : FROM python:2.7-slim
2.7-slim: Pulling from library/python
ad74af05f5a2: Pulling fs layer 
8812637047e3: Pulling fs layer 
be169522399f: Pulling fs layer 
286703095347: Waiting 
error pulling image configuration: Get https://dseasb33srnrn.cloudfront.net/registry-v2/docker/registry/v2/blobs/sha256/45/451c85955bc2512838b77c3d26db434f32b9e1f532472d0869d4a719fc179ac6/data?Expires=1504856139&Signature=KzkIc3MDDMJ0wGZctxz~OJu2XoBsJNe1y0v5cLd31g6cCmeLIbgtvaJaAoO7hBDZpELpl~lzzBB2Gz7AV4xAr41v-5Qf7ylZwreaHQ65Fyoelok4vrtGBvoGktW2Rzz-gQPcKaQ5KJwbOvRO6qOYKbnQT8HmUuzECld4YDbAiss_&Key-Pair-Id=APKAJECH5M7VWIS5YZ6Q: dial tcp: lookup dseasb33srnrn.cloudfront.net on 192.168.65.1:53: read udp 192.168.65.2:47936->192.168.65.1:53: i/o timeout

又是i/o timeout的问题。 
怎能放弃治疗?!于是又使用了stackoverflow大法: 
改DNS地址为8.8.8.8 
这时候再run一遍命令,神奇地开始下载了…… 
如果你看到这个长长长长的安装内容以及最后一句successfully,说明你已经成功build了docker的app环境。

➜  docker-image-files docker build -t friendlyhello .
Sending build context to Docker daemon  4.608kB
Step 1/7 : FROM python:2.7-slim
2.7-slim: Pulling from library/python
ad74af05f5a2: Pull complete 
8812637047e3: Pull complete 
be169522399f: Pull complete 
286703095347: Pull complete 
Digest: sha256:5d668aa50cac534b08df02d942a6d1e9e71b38da9386ee54b3312be0af138469
Status: Downloaded newer image for python:2.7-slim
 ---> 451c85955bc2
Step 2/7 : WORKDIR /app
 ---> 08ccfba76a50
Removing intermediate container 3c5879c8130f
Step 3/7 : ADD . /app
 ---> 3fe444ae9b98
Removing intermediate container 8a2d221f93ee
Step 4/7 : RUN pip install -r requirements.txt
 ---> Running in e37e45584db6
Collecting Flask (from -r requirements.txt (line 1))
  Downloading Flask-0.12.2-py2.py3-none-any.whl (83kB)
Collecting Redis (from -r requirements.txt (line 2))
  Downloading redis-2.10.6-py2.py3-none-any.whl (64kB)
Collecting itsdangerous>=0.21 (from Flask->-r requirements.txt (line 1))
  Downloading itsdangerous-0.24.tar.gz (46kB)
Collecting Jinja2>=2.4 (from Flask->-r requirements.txt (line 1))
  Downloading Jinja2-2.9.6-py2.py3-none-any.whl (340kB)
Collecting Werkzeug>=0.7 (from Flask->-r requirements.txt (line 1))
  Downloading Werkzeug-0.12.2-py2.py3-none-any.whl (312kB)
Collecting click>=2.0 (from Flask->-r requirements.txt (line 1))
  Downloading click-6.7-py2.py3-none-any.whl (71kB)
Collecting MarkupSafe>=0.23 (from Jinja2>=2.4->Flask->-r requirements.txt (line 1))
  Downloading MarkupSafe-1.0.tar.gz
Building wheels for collected packages: itsdangerous, MarkupSafe
  Running setup.py bdist_wheel for itsdangerous: started
  Running setup.py bdist_wheel for itsdangerous: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/fc/a8/66/24d655233c757e178d45dea2de22a04c6d92766abfb741129a
  Running setup.py bdist_wheel for MarkupSafe: started
  Running setup.py bdist_wheel for MarkupSafe: finished with status 'done'
  Stored in directory: /root/.cache/pip/wheels/88/a7/30/e39a54a87bcbe25308fa3ca64e8ddc75d9b3e5afa21ee32d57
Successfully built itsdangerous MarkupSafe
Installing collected packages: itsdangerous, MarkupSafe, Jinja2, Werkzeug, click, Flask, Redis
Successfully installed Flask-0.12.2 Jinja2-2.9.6 MarkupSafe-1.0 Redis-2.10.6 Werkzeug-0.12.2 click-6.7 itsdangerous-0.24
 ---> a81e2bc9de84
Removing intermediate container e37e45584db6
Step 5/7 : EXPOSE 80
 ---> Running in 1a42c917a0d5
 ---> 0dc7297ab9cd
Removing intermediate container 1a42c917a0d5
Step 6/7 : ENV NAME World
 ---> Running in df9e70eb4d1b
 ---> 2fa8053a651b
Removing intermediate container df9e70eb4d1b
Step 7/7 : CMD python app.py
 ---> Running in e183136d2fd4
 ---> 46f195936dee
Removing intermediate container e183136d2fd4
Successfully built 46f195936dee
Successfully tagged friendlyhello:latest

命令行里输入 docker images,显然安装成功了。

$ docker-image-files docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
friendlyhello       latest              46f195936dee        10 minutes ago      194MB
python              2.7-slim            451c85955bc2        6 weeks ago         182MB

接着愉快滴看到docker跑起来啦!

➜  docker-image-files docker run -p 4000:80 friendlyhello
 * Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
172.17.0.1 - - [08/Sep/2017 08:05:38] "GET / HTTP/1.1" 200 -
172.17.0.1 - - [08/Sep/2017 08:05:38] "GET /favicon.ico HTTP/1.1" 404 -

这里写图片描述 
我直接conmand+c关掉了docker的app。

本文转载自:https://blog.csdn.net/voilethht/article/details/77895275

共有 人打赏支持
writeademo
粉丝 23
博文 516
码字总数 188548
作品 0
东城
从零开始搭建Jenkins+Docker自动化集成环境

本文只简单标记下大概的步骤,具体搭建各个部分的细节,还请自行搜索。第一、二部分只是对Jenkins和Docker的简单介绍,熟悉的同学请直接跳到第三部分。 Jenkins可以帮你构建一个自动化的持续...

林杰
2016/09/05
0
0
如何通过Rancher webhook微服务实现Service/Host的弹性伸缩

概述 结合大家CICD的应用场景,本篇Blog旨在介绍如何通过Rancher的webhook微服务来实现Service/Host的弹性伸缩。 流程介绍 Service Scale Host Sacle webhook介绍 Rancher webhook的服务流程...

RancherLabs
2017/10/11
0
0
重磅消息!Docker宣布支持Kubernetes!

  【IT168 编译】重磅新闻!Docker本周在DockerCon Europe会议上宣布,Kubernetes将整合到Docker平台上,Kubernetes是用于自动化容器部署,扩展和管理的开源系统。   作为Docker平台更新的...

it168网站
2017/10/18
0
0
『中级篇』如何在mac上安装docker(五)

人与动物最大的区别就是,人会使用工具。在二线城市可能不太明显,一线开发和运维一般都是使用的电脑都是mac,因为mac更接近服务器的linux操作系统。 mac安装的官网介绍 docker官网mac安装 ...

IT人故事会
05/27
0
0
Mac平台上Docker安装与使用

Docker是一个跨平台的轻量级虚拟机,可移植性非常高,一次部署,终生可用。Docker可以在Linux,Windows,MacOS等平台上安装使用。我们都知道Linux有很多不同 的版本,例如Ubuntu,AIX,CentOS,...

jiang_xinxing
2017/02/27
0
0

没有更多内容

加载失败,请刷新页面

加载更多

00.编译OpenJDK-8u40的整个过程

前言 历经2天的折腾总算把OpenJDK给编译成功了,要说为啥搞这个,还得从面试说起,最近出去面试经常被问到JVM的相关东西,总感觉自己以前学的太浅薄,所以回来就打算深入学习,目标把《深入理...

凌晨一点
今天
2
0
python: 一些关于元组的碎碎念

初始化元组的时候,尤其是元组里面只有一个元素的时候,会出现一些很蛋疼的情况: def checkContentAndType(obj): print(obj) print(type(obj))if __name__=="__main__": tu...

Oh_really
昨天
6
2
jvm crash分析工具

介绍一款非常好用的jvm crash分析工具,当jvm挂掉时,会产生hs_err_pid.log。里面记录了jvm当时的运行状态以及错误信息,但是内容量比较庞大,不好分析。所以我们要借助工具来帮我们。 Cras...

xpbob
昨天
119
0
Qt编写自定义控件属性设计器

以前做.NET开发中,.NET直接就集成了属性设计器,VS不愧是宇宙第一IDE,你能够想到的都给你封装好了,用起来不要太爽!因为项目需要自从全面转Qt开发已经6年有余,在工业控制领域,有一些应用...

飞扬青云
昨天
4
0
我为什么用GO语言来做区块链?

Go语言现在常常被用来做去中心化系统(decentralised system)。其他类型的公司也都把Go用在产品的核心模块中,并且它在网站开发中也占据了一席之地。 我们在决定做Karachain的时候,考量(b...

HiBlock
昨天
2
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部