目录
记录一下使用的 Docker 的辛苦过程。
Docker 使用的范围越来越广,我最看重的就是环境隔离,和环境整体打包服务,不用再自己的本地环境上编译。
本文以 CentOS 7 来作为记录过程,其他的发行版类似,就一些系统级别的命令可能不合适。
安装
yum insatll docker
重启
systemctl daemon-reload
systemctl restart docker
本地镜像加速
出现
root@VM_96_130_centos tmp]# docker pull mysql:5.7
Trying to pull repository docker.io/library/mysql ...
Pulling repository docker.io/library/mysql
Error while pulling image: Get https://index.docker.io/v1/repositories/library/mysql/images: dial tcp 52.207.59.176:443: getsockopt: network is unreachable
Error while pulling image: Get https://index.docker.io/v1/repositories/library/mysql/images: dial tcp 52.207.59.176:443: getsockopt: network is unreachable
我这里使用的是腾讯云,因此我这里的是镜像加速和下载
vim /usr/lib/systemd/system/docker.service
ExecStart=/usr/bin/docker-current daemon \ --exec-opt native.cgroupdriver=systemd \ --registry-mirror=https://mirror.ccs.tencentyun.com \ -g /data/docker/ \ $OPTIONS \ $DOCKER_STORAGE_OPTIONS \ $DOCKER_NETWORK_OPTIONS \ $ADD_REGISTRY \ $BLOCK_REGISTRY \ $INSECURE_REGISTRY
顺便更改一下 docker 镜像的路径,防止系统根目录太小。
网上也有说 /etc/default/docker为啥不起作用的。
HTTP 代理
利用 docker build -t xxx .
出现一些错误
Ign http://archive.ubuntu.com trusty InRelease
Ign http://archive.ubuntu.com trusty-updates InRelease
Ign http://archive.ubuntu.com trusty-security InRelease
Err http://archive.ubuntu.com trusty Release.gpg
Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8001::21 80]
Err http://archive.ubuntu.com trusty-updates Release.gpg
Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8001::21 80]
Err http://archive.ubuntu.com trusty-security Release.gpg
Cannot initiate the connection to archive.ubuntu.com:80 (2001:67c:1360:8001::21). - connect (101: Network is unreachable) [IP: 2001:67c:1360:8001::21 80]
修改 Dockerfile ,增加http代理
FROM ubuntu:14.04 MAINTAINER Kevin Littlejohn <kevin@littlejohn.id.au>, \ Alex Fraser <alex@vpac-innovations.com.au> # 这个是可用的 ENV http_proxy=http://xx.xx.xx.xx:6788/ ENV https_proxy=http://xx.xx.xx.xx:6788/ # 网上有这么说的,这个是不能用于 ubuntu的agt-get。 ENV HTTP_PROXY=http://xx.xx.xx.xx:6788/ ENV HTTPS_PROXY=http://xx.xx.xx.xx:6788/
目前没有找到一个说法,http_proxy
是否应该大写。应该是不同的程序读取的环境变量不一样,我看大部分都是小写,最好的方法是都设置。
常用的命令记录
docker build
# 编写 Dockerfile 文件
docker build -t docker-proxy .
docker images
查看镜像
docker exec
# 进入容器内部
docker exec -it 容器id /bin/bash
docker run
# 打开镜像看看
# 因为有时候直接启动会被退出了。
docker run -i -t ubuntu:14.04 /bin/bash
docker-compose
pip install docker-compose
# 编写 docker-compose.yml 文件
docker-compose up -d
其他的系统也有依赖 docker 的,出现了
File "/root/readthedocs/readthedocs.org/readthedocs/doc_builder/environments.py", line 16, in <module>
from docker import Client
ImportError: cannot import name Client
那么其他使用 virtualenv
来解决单独的部署问题,让默认的系统能够正常使用。
声明:未经允许禁止转载 东东东 陈煜东的博客 文章,谢谢。如经授权,转载请注明: 转载自东东东 陈煜东的博客
本文链接地址: Docker 实践记录 – https://www.chenyudong.com/archives/docker-practice.html
2017 年 4 月 19 日 — 14:26
您好,想请教您关于docker方面的问题,可以发邮件给我吗?
2017 年 4 月 21 日 — 13:32
有什么问题,可以这里留言交流一下。