原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://dgd2010.blog.51cto.com/1539422/1729858

虽然本文标题是针对Ubuntu的,但对于CentOS也是可以变通的,无非是几个命令不完全相同,有经验的人可以自行修改,部分不容易找的包或者命令已经在文档中作出了注释,可以作为参考。

目录导航:

  • 安装Docker引擎服务

  • 安装docker-enter工具,便于使用docker

  • 安装docker-registry服务

  • 支持HTTPS的docker-registry服务

    • 编译安装nginx

    • 免费制作https所需的可被权威CA认证的SSL证书(DV Certificates)

    • 配置nginx https服务

  • 验证最终结果

  • CentOS运行python2.7的方法

(1)系统初始化完成后开始安装Docker引擎服务

# for service docker

# Refer: https://www.docker.com/

# Refer: https://docs.docker.com/linux/step_one/

静默更新系统,-qq参数需要用在apt-get子命令之前,-y随意

1
apt-get -qq update -y

安装wget工具用于下载文件

1
which wget  > /dev/null || apt-get -qq install -y wget

添加docker的软件仓库key

1
wget -qO- https://get.docker.com/gpg | apt-key add -

执行docker安装程序

1
wget -qO- https://get.docker.com/ | sh

执行docker的测试命令,通过此命令看一看到docker引擎的版本等信息

1
docker version

# If you would like to use Docker as a non-root user, you should now consider adding your user to the "docker" group with something like:

# sudo usermod -aG docker your-user

(2)安装docker-enter工具,便于使用docker

# for program docker-enter

# Refer: http://dockerpool.com/static/books/docker_practice/container/enter.html

安装curl用于下载文件,此步骤可以省略,但建议安装

1
which curl > /dev/null || apt-get -qq install -y curl

下载并解压util工具,编译并安装nsenter,nsenter是docker-enter的主要组件

#cd /tmp; curl https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.gz | tar -zxf-; cd util-linux-2.24;

1
2
3
4
5
6
cd /tmp; wget -q https://www.kernel.org/pub/linux/utils/util-linux/v2.24/util-linux-2.24.tar.gz; tar xzvf util-linux-2.24.tar.gz
cd util-linux-2.24
./configure --without-ncurses && make nsenter
cp nsenter '/usr/local/bin'
which nsenter
cd

下载.bashrc_docker文件,并将此文件添加到当前用户的bash初始化文件中

1
2
wget -P ~ https://github.com/yeasy/docker_practice/raw/master/_local/.bashrc_docker;
echo "[ -f ~/.bashrc_docker ] && . ~/.bashrc_docker" >> ~/.bashrc; source ~/.bashrc

(3)安装docker-registry服务

# for service docker-registry

静默安装依赖软件docker-registry的软件包,执行安装程序

1
apt-get -qq -y install build-essential python-dev libevent-dev python-pip libssl-dev liblzma-dev libffi-dev swig

从github获取docker-registry,安装方式还有其他几种,可以参考官方文档https://docs.docker.com/registry/deploying/

1
2
3
git clone https://github.com/docker/docker-registry.git
cd docker-registry
python setup.py install

如果目录存在则进入目录

1
test -d '/usr/local/lib/python2.7/dist-packages/docker_registry-1.0.0_dev-py2.7.egg/config/' && cd /usr/local/lib/python2.7/dist-packages/docker_registry-1.0.0_dev-py2.7.egg/config/

以config_sample.yml模板创建config.yml文件

1
cp config_sample.yml config.yml

以后台程序的方式运行gunicorn,以启动docker-registry

1
nohup gunicorn --access-logfile - --error-logfile - -k gevent -b 0.0.0.0:5000 -w 4 --max-requests 100 docker_registry.wsgi:application >>/tmp/docker-registry.log &

如果要结束docker-registry则执行killall gunicorn

1
killall gunicorn

配置docker可以使用刚刚配置好的docker-registry

把docker.domain.com改成你的域名,后面在配置支持HTTPS的docker-registry服务时会继续使用。

1
2
3
# Insecure Registry, Deploying a plain HTTP registry,Using self-signed certificates 
grep insecure /etc/default/docker || echo 'DOCKER_OPTS="--insecure-registry docker.domain.com:5000"' >> /etc/default/docker
service docker stop && service docker start

(4)配置支持HTTPS的docker-registry服务

编译安装nginx

1
2
3
4
5
6
7
8
9
10
11
12
13
14
wget http://nginx.org/download/nginx-1.8.0.tar.gz  
tar zxf nginx-1.8.0.tar.gz  
wget ftp://ftp.csx.cam.ac.uk/pub/software/programming/pcre/pcre-8.37.tar.gz  
tar zxf pcre-8.37.tar.gz  
wget https://www.openssl.org/source/openssl-1.0.2e.tar.gz  
tar zxf openssl-1.0.2e.tar.gz  
wget http://zlib.net/zlib-1.2.8.tar.gz  
tar zxf zlib-1.2.8.tar.gz  
groupadd -r www  
useradd -r -g www www -c "Web user" -d /dev/null -s /sbin/nologin  
cd nginx-1.8.0  
./configure --prefix=/usr/local/nginx --with-http_ssl_module --user=www --group=www --with-pcre=/root/pcre-8.37 --with-zlib=/root/zlib-1.2.8 --with-openssl=/root/openssl-1.0.2e  
make && make install  
/usr/local/nginx/sbin/nginx -V

免费制作https所需的可被权威CA认证的SSL证书(DV Certificates)

制作证书可以自己制作自签名证书,既可以使用Windows自带的证书服务,也可以使用OpenSSL工具,但弊端是用户必须安装CA证书,浏览器才能承认此证书。如果想申请互联网公认的证书必须由公认的权威CA签发,这样的证书通常需要购买或者试用获得。如果不想花钱或者试用,可以借助Let’s Encrypt CA项目,自己给自己发放管理证书。

Let’s Encrypt CA项目是由Mozilla、思科、Akamai、IdenTrust、EFF和密歇根大学研究人员等共同创建的 ,项目官方网站是https://letsencrypt.org/,Github项目网站是https://github.com/letsencrypt/letsencrypt。此项目为网站(个人网站、非个人网站)提供免费SSL证书,向任何需要加密证书的网站自动发行和管理免费证书。

系统要求(先决条件):

  1. python2.6以上(不含python2.6),CentOS系统默认安装的是python2.6,CentOS升级python的方法参照下文。

  2. 要申请的证书的common name也就是证书使用者(持有人)的域名需要指向当前客户端所在的主机,例如你要给自己的网站域名为www.domian.com申请证书,则www.domain.com必须与你执行下列步骤时所在的主机是同一个主机(域名解析到此主机,不区分A记录还是CNAME记录),原因是在生成证书的过程中letsencrypt服务器会与当前客户端进行通信,如果不是同一个主机则将导致无法通过验证或者通信失败,进而导致证书生成失败。 如果,域名不是DNS运营商来得到的,则可以尝试修改hosts文件。例如在Linux下,修改/etc/hosts文件,添加your_ip_address www.yourdomainname.com条目即可。

1
2
3
git clone https://github.com/letsencrypt/letsencrypt  
cd letsencrypt  
./letsencrypt-auto certonly --standalone --email dgdenterprise@gmail.com -d www.domain.com

命令会自动根据当前的操作系统下载合适的依赖包(主要是python),并且判断当前系统环境是否满足生成证书的要求,如果不满足系统要求,则该程序会显示出警告或者错误信息。

在命令成功完成后会有较为明显的提示,生成的证书将存放在/etc/letsencrypt/live/www.domain.com/目录下,这个目录下的文件是/etc/letsencrypt/archive/www.domain.com/下的符号链接文件

配置nginx https服务

有了证书和key就可以开始配置nginx https服务了。

可选步骤,(尚未验证,读者可忽略此段斜体文字)为docker-registry设置身份验证,需要用到Apache项目中的htpasswd,在CentOS中htpasswd位于httpd-tools包中

1
2
# for htpasswd 
apt-get -qq -y install apache2-utils

配置nginx https服务,有两种选择,即可以像配置nginx http服务那样一步一步新建虚拟主机,也可以直接用https代理http。此处选择后者,简单易行。

1
mkdir /usr/local/nginx/conf/vhost

# sed在文件最后一行的上一行插入新行,如果是最后一行插入新行,则可以将i换成a

1
sed -i '$i include vhost/*.conf;' /usr/local/nginx/conf/nginx.conf

# 注意:把下文中的www.yourdomainname.com换成想设置的域名  
#注意:把下文中的docker-registry-server换成上文监听5000端口的某个IP地址,建议将此IP地址使用内网IP地址

1
vim /usr/local/nginx/conf/vhost/https_www.yourdomainname.com.conf

server {  
        listen 443 ssl;  
        server_name www.yourdomainname.com;  
        index index.html index.htm;  
        
        ssl on;  
        ssl_certificate /etc/letsencrypt/live/www.yourdomainname.com/fullchain.pem;  
        ssl_certificate_key /etc/letsencrypt/live/www.yourdomainname.com/privkey.pem;  
        #ssl_password_file /usr/local/;

location / {  
            client_max_body_size    0;  
            proxy_connect_timeout 300s;  
            proxy_send_timeout   900;  
            proxy_read_timeout   900;  
            proxy_buffer_size    32k;  
            proxy_buffers      4 32k;  
            proxy_busy_buffers_size 64k;  
            proxy_redirect     off;  
            proxy_hide_header  Vary;  
            proxy_set_header   Accept-Encoding '';  
            proxy_set_header   Host   $host;  
            proxy_set_header   Referer $http_referer;  
            proxy_set_header   Cookie $http_cookie;  
            proxy_set_header   X-Real-IP  $remote_addr;  
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
            proxy_set_header   Host $host;  
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;           
            proxy_headers_hash_max_size 51200;  
            proxy_headers_hash_bucket_size 6400;  
            proxy_pass         http://docker-registry-server/;  
        }

}

1
vim /usr/local/nginx/conf/vhost/http_www.yourdomainname.com.conf

server {  
        listen 80;  
        server_name www.yourdomainname.com;  
        index index.html index.htm;

location / {  
            client_max_body_size    0;  
            proxy_connect_timeout 300s;  
            proxy_send_timeout   900;  
            proxy_read_timeout   900;  
            proxy_buffer_size    32k;  
            proxy_buffers      4 32k;  
            proxy_busy_buffers_size 64k;  
            proxy_redirect     off;  
            proxy_hide_header  Vary;  
            proxy_set_header   Accept-Encoding '';  
            proxy_set_header   Host   $host;  
            proxy_set_header   Referer $http_referer;  
            proxy_set_header   Cookie $http_cookie;  
            proxy_set_header   X-Real-IP  $remote_addr;  
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;  
            proxy_set_header   Host $host;  
            proxy_set_header   X-Forwarded-For $proxy_add_x_forwarded_for;           
            proxy_headers_hash_max_size 51200;  
            proxy_headers_hash_bucket_size 6400;  
            proxy_pass         http://docker-registry-server/;  
        }

}

1
2
/usr/local/nginx/sbin/nginx -t 
/usr/local/nginx/sbin/nginx -s reload

(5)验证最终结果

此时可以使用docker命令,将从其他地方导入的images或从hub.docker.com网站pull的镜像,commit或tag成www.yourdomainname.com/imagesname ,然后push到自己建的docker-registry上。

附加:CentOS将python2.6切换到python2.7的方法

文章可以参考《How to install Python 2.7 and Python 3.3 on CentOS 6》或《Installing python 2.7 on centos 6.3. Follow this sequence exactly for centos machine only》。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
yum groupinstall -y "Development tools"
yum install -y zlib-devel bzip2-devel openssl-devel ncurses-devel sqlite-devel readline-devel tk-devel gdbm-devel db4-devel libpcap-devel xz-devel
echo '/usr/local/lib' >> /etc/ld.so.conf
ldconfig
# Python 2.7.6:
wget -c http://python.org/ftp/python/2.7.6/Python-2.7.6.tar.xz
tar xf Python-2.7.6.tar.xz
cd Python-2.7.6
./configure --prefix=/usr/local --enable-unicode=ucs4 --enable-shared LDFLAGS="-Wl,-rpath /usr/local/lib"
make && make altinstall
cd
# First get the setup script for Setuptools:
wget -c https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py
python2.7 ez_setup.py
easy_install-2.7 pip
# Install virtualenv for Python 2.7 and create a sandbox called my27project:
pip2.7 install virtualenv
virtualenv-2.7 my27project
# Check the system Python interpreter version:
python --version
# This will show Python 2.6.6
# Activate the my27project sandbox and check the version of the default Python interpreter in it:
source my27project/bin/activate
python --version
# This will show Python 2.7.6
# 在这里运行生成证书的程序
# 生成证书完毕后执行deactivate,退出virtualenv
deactivate

tag:Ubuntu安装docker,Ubuntu安装docker-registry,Ubuntu安装docker-enter,Ubuntu安装docker引擎,Ubuntu 容器虚拟化

--end--

本文出自 “通信,我的最爱” 博客,请务必保留此出处http://dgd2010.blog.51cto.com/1539422/1729858

Ubuntu安装Docker引擎和支持HTTPS的docker-registry服务相关推荐

  1. ubuntu安装符号执行引擎KLEE

    背景:ubuntu20.04上安装klee2.2 官网安装教程:KLEE2-2安装教程(不是很详细,仅参考) 本文的安装环境全部放在/opt/klee_env下,root用户下执行命令 1.安装必备工 ...

  2. nginx安装配置ssl模块支持https访问

    文章目录 一.SSL证书 申请免费证书或者购买 1.证书下载 2.配置Nginx 常见错误 错误一: 解决方案: 错误二: 解决方案: 错误三:配置好后https仍然无法访问 情况1:端口443未开放 ...

  3. Ubuntu 安装docker CE以及harbor

    Docker CE安装 系统建议版本:Ubuntu 16.04 官方安装文档连接:https://docs.docker.com/install/linux/docker-ce/ubuntu/#pre ...

  4. ubuntu 安装docker_Docker: 教程04 - (初始化安装之在 Ubuntu 安装Docker CE)

    创建 Ubuntu 运行环境 首先我们需要创建一个 Ubuntu 运行环境,在云环境中,我们创建了一个版本为 "Ubuntu 18.04 Bionic Beaver LTS" ,大 ...

  5. ubuntu安装docker详细教程以及配置阿里云镜像加速

    ubuntu环境: Distributor ID: Ubuntu Description:    Ubuntu 16.04.2 LTS Release:        16.04 Codename: ...

  6. E: 无法下载 https://download.docker.com/linux/ubuntu/dists/Xenial/stable/binary-amd64/Packages 404 Not

    E: 无法下载 https://download.docker.com/linux/ubuntu/dists/Xenial/stable/binary-amd64/Packages 404 Not F ...

  7. 【转】借助第三方支持https协议的存储实现自己网站上扫描二维码安装IOS APP

    使用plist安装,一般是企业级开发者账号不需要登录到APP STORE的IOS设备应用发布时所用到的技巧. 准备: *一台运行着OSX的苹果电脑,最新版的XCODE,用于导出ipa和plist 一个 ...

  8. ubuntu安装nvidia显卡驱动+cuda9.0+cudnn7.0+查看cuda版本+安装tensorrt+python查看gpu显存

    一,驱动安装 显卡驱动和cuda版本关系 卸载原先驱动 sudo apt-get remove --purge nvidia-\* ubuntu-drivers devices  查看显卡类型 Nvi ...

  9. Windows10下的docker安装与入门 (一)使用docker toolbox安装docker

    Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中,然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全使用沙箱机制,相互之间不会有任何 ...

最新文章

  1. 蚂蚁的金融交易系统架构
  2. android之http协议编程(源码ppt),Android网络编程(八)源码解析OkHttp中篇[复用连接池]...
  3. 特征级融合_更丰富的卷积特征用于目标边缘检测(文末附有论文及源码下载)...
  4. spring框架 AOP核心详解
  5. 台积电6月营收环比大增 或预示苹果A14处理器已大规模出货
  6. 小学计算机辅导计划,【小学信息技术培优补差计划】_小学信息技术培优补差计划...
  7. java 任务_Java-定时任务
  8. 后序遍历的非递归算法python_Python非递归实现二叉树的后续遍历
  9. Pytorch Tensor.unfold()的简单理解与用法
  10. 使用DotNetOpenAuth搭建OAuth2.0授权框架——Demo代码简单说明
  11. 【漏扫工具】AWVS12使用介绍
  12. 【SQL基础】SQL查询语句实例
  13. STM32 FFT算法实现
  14. 麦当劳如何吸引消费者走进店里
  15. mac系统如何新建文件
  16. r语言中popsd和sd的区别_R语言中回归和分类模型选择的性能指标
  17. 雷达遥感原理;侧视雷达成像系统;雷达回波强度的影响因素;雷达遥感及雷达图像的特征
  18. 给自己的一封信(给未来,也给现在)
  19. Java入门小练习:征婚条件
  20. 阿里巴巴马云:成功创业三大拷问

热门文章

  1. Java高并发编程详解系列-线程池原理自定义线程池
  2. 详解 Qt 串口通信程序全程图文 (3)
  3. 深入学习用Go编写HTTP服务器
  4. springboot整合MyCat
  5. Spring Boot注解详解
  6. 数据库 case when then 的用法 (举个栗子~~~)
  7. CArray动态数组
  8. 云效(原RDC)+ 容器服务完成持续集成
  9. javascript的BOM
  10. C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 服务器之间的接口通讯功、信息交换...