现象

根据 官方文档示例 进行操作,执行过程中遇到下面的问题

Cappuccinooos-MacBook-Pro:docker Cappuccinooo$ sudo docker build -t friendlyhello .
Password:
Sending build context to Docker daemon  4.608kB
Step 1/7 : FROM python2.7-slim
pull access denied for python2.7-slim, repository does not exist or may require 'docker login'

排查过程

根据错误提示是:repository不存在或者需要运行docker login登录,但是根据官方文档:在docker hub中搜索或者拉去images时并不需要账户并且登录,如图1:
图1

google相关问题,在Stackoverflow上的类似这个回答Docker hello-world: authentication error中可以找到一些线索:
图2

根据图2来看,还是需要使用账号和密码去登录的,不然也不会有那么多人问这个相关的问题;

于是乖乖的去docker hub官网创建Docker id,创建过程略过,成功登录的界面如下:

Docker hub

然后在运行docker build -t friendlyhello .命令之前先使用命令docker login登录,过程如下:

Cappuccinooos-MacBook-Pro:docker Cappuccinooo$ docker login
Login with your Docker ID to push and pull images from Docker Hub. If you don't have a Docker ID, head over to https://hub.docker.com to create one.
Username: cappuccinooo
Password:
Login Succeeded

最终原因

发现还是报上面的错误,网上查了半天,最后在这里找到了疑似答案,如图:
这里写图片描述

受此启发,检查Dockerfile,发现FROM python:2.7-slim,少写了个冒号: ,最终导致出现了此问题,修改后镜像制作成功

Cappuccinooos-MacBook-Pro:docker Cappuccinooo$ 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
f2aa67a397c4: Pull complete
e2199a29f304: Pull complete
268f45f063ba: Pull complete
349902594a9c: Pull complete
Digest: sha256:703bb6080c6a364d99d2dcac6ba559859efaa590de39616a5605bbf5e312a234
Status: Downloaded newer image for python:2.7-slim
 ---> d0d1b97dd328
Step 2/7 : WORKDIR /app
Removing intermediate container 80516103fbaa
 ---> 041ecf13efd2
Step 3/7 : ADD . /app
 ---> 057a38260da9
Step 4/7 : RUN pip install -r requirements.txt
 ---> Running in c5eca637525e
Collecting Flask (from -r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/7f/e7/08578774ed4536d3242b14dacb4696386634607af824ea997202cd0edb4b/Flask-1.0.2-py2.py3-none-any.whl (91kB)
Collecting Redis (from -r requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/3b/f6/7a76333cf0b9251ecf49efff635015171843d9b977e4ffcf59f9c4428052/redis-2.10.6-py2.py3-none-any.whl (64kB)
Collecting itsdangerous>=0.24 (from Flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/dc/b4/a60bcdba945c00f6d608d8975131ab3f25b22f2bcfe1dab221165194b2d4/itsdangerous-0.24.tar.gz (46kB)
Collecting Jinja2>=2.10 (from Flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/7f/ff/ae64bacdfc95f27a016a7bed8e8686763ba4d277a78ca76f32659220a731/Jinja2-2.10-py2.py3-none-any.whl (126kB)
Collecting Werkzeug>=0.14 (from Flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/20/c4/12e3e56473e52375aa29c4764e70d1b8f3efa6682bef8d0aae04fe335243/Werkzeug-0.14.1-py2.py3-none-any.whl (322kB)
Collecting click>=5.1 (from Flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/34/c1/8806f99713ddb993c5366c362b2f908f18269f8d792aff1abfd700775a77/click-6.7-py2.py3-none-any.whl (71kB)
Collecting MarkupSafe>=0.23 (from Jinja2>=2.10->Flask->-r requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/4d/de/32d741db316d8fdb7680822dd37001ef7a448255de9699ab4bfcbdf4172b/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/2c/4a/61/5599631c1554768c6290b08c02c72d7317910374ca602ff1e5
  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/33/56/20/ebe49a5c612fffe1c5a632146b16596f9e64676768661e4e46
Successfully built itsdangerous MarkupSafe
Installing collected packages: itsdangerous, MarkupSafe, Jinja2, Werkzeug, click, Flask, Redis
Successfully installed Flask-1.0.2 Jinja2-2.10 MarkupSafe-1.0 Redis-2.10.6 Werkzeug-0.14.1 click-6.7 itsdangerous-0.24
Removing intermediate container c5eca637525e
 ---> fa672c1cb817
Step 5/7 : EXPOSE 80
 ---> Running in 6243c4881c15
Removing intermediate container 6243c4881c15
 ---> 1d7df5055dbd
Step 6/7 : ENV NAME Word
 ---> Running in c48b286d033a
Removing intermediate container c48b286d033a
 ---> c4a2a5521529
Step 7/7 : CMD ["python","app.py"]
 ---> Running in e57feeafa6ca
Removing intermediate container e57feeafa6ca
 ---> bebe70734349
Successfully built bebe70734349
Successfully tagged friendlyhello:latest

总结

再次确认了下官方文档的示例,是自己大意写错了,也好,算一次锻炼自己排查问题的机会

官方文档示例
这里写图片描述

Logo

权威|前沿|技术|干货|国内首个API全生命周期开发者社区

更多推荐