docker官方文档-part2
来源:互联网 发布:ubuntu qq2012国际版 编辑:程序博客网 时间:2024/06/17 17:40
Dockerfile
# Use an official Python runtime as a parent imageFROM python:2.7# Set the working directory to /appWORKDIR /app# Copy the current directory contents into the container at /appADD . /app# Install any needed packages specified in requirements.txtRUN pip install -r requirements.txt# Make port 80 available to the world outside this containerEXPOSE 80# Define environment variableENV NAME World# Run app.py when the container launchesCMD ["python", "app.py"]
requirements.txt
FlaskRedia
app.py
from flask import Flaskfrom redis import Redis, RedisErrorimport osimport socket# Connect to Redisredis = 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)
开始build镜像
sudo docker build -t hello .
会发现上面这样的错误。主要原因是在容器内无法使用网络。
解决办法
可以看到IP4.DNS是202.120.80.2
如果不存在/etc/docker/daemon.json文件,创建一个并编辑为
重启docker服务
sudo service docker restart
如果使用Dockerfile build镜像时需要执行apt-get update操作,可以在Dockerfile中修改容器的镜像源来加速。
RUN sed -i 's/http:\/\/archive.ubuntu.com\/ubuntu\//http:\/\/mirrors.163.com\/ubuntu\//g' /etc/apt/sources.list
重启docker服务之后再次build镜像,可以看到这次没有出现错误
运行容器
发布自己的镜像
首先需要为镜像打上标签,命令的格式为:
sudo docker tag image username/repository:tag
username是在docker hub上注册了的账户名,否则无法push自己的镜像
登录自己的账户
push镜像
然后可以到自己的docker hub上查看push的镜像,也可以通过
docker search指令查找到镜像,但好像刚刚push的镜像还搜不到。
阅读全文
0 0
- docker官方文档-part2
- [Docker 官方文档] 理解 Docker
- docker官方文档
- Docker安全性——官方文档[译]
- Ubuntu安装Docker(官方文档翻译)
- docker安装telnet 命令【官方文档】
- Spring Boot Docker化官方文档
- Docker 官方速查文档下载、安装和使用指南
- Docker 文档
- Part2-HttpClient官方教程-Chapter1-基础
- Part2-HttpClient官方教程-Chapter2-连接管理
- 官方文档
- 官方文档
- Docker官方文档笔记——创建自己的image初窥,和Inspect,port命令
- openstack官方docker介绍
- docker官方手册
- Docker官方教程
- Docker官方入门教程
- 将Marvell 88W8686 WiFi模块的固件内容写入到STM32F103RE单片机Flash末尾的固定位置
- FFMPEG Qt录屏软件开发之视频采集
- 新建Maven项目只有resource目录
- gps坐标转换
- MD5原理
- docker官方文档-part2
- Qt 发布应用程序
- 闭包 和闭包的作用
- LeetCode.289 Game of Life
- CodeForces
- FFmpeg录屏软件开发之屏幕录像
- HDU 3923 Invoker (polya定理)
- 离散数学中关于等价与相容的一些理解
- 0-1背包问题