docker install

ubuntu install docker

  • 从Ubuntu仓库下载安装
apt update
apt install docker.io 
  • 从Docker 仓库下载安装

Uninstall old versions

sudo apt-get remove docker docker-engine docker.io containerd runc

Install Docker CE

sudo apt-get update
sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
apt-cache madison docker-ce

docker run --rm hello-world

Get Docker CE for Ubuntu

镜像加速器

配置镜像加速器

针对Docker客户端版本大于 1.10.0 的用户

Ubuntu 16.04+、Debian 8+、CentOS 7+

您可以通过修改daemon配置文件/etc/docker/daemon.json来使用加速器

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://9fgvz9iu.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

镜像地址

{
  "registry-mirrors": [
        "https://9fgvz9iu.mirror.aliyuncs.com",
        "http://f1361db2.m.daocloud.io",
        "https://dockerhub.azk8s.cn",
        "https://reg-mirror.qiniu.com",
        "https://mirror.ccs.tencentyun.com"
  ]
}

docker hub 镜像测速

使用镜像前后,可使用 time 统计所花费的总时间。测速前先移除本地的镜像!

root@iZ2ze3wh0gny7gw4zybnycZ:~# docker rmi node:latest
root@iZ2ze3wh0gny7gw4zybnycZ:~# time docker pull node:latest
latest: Pulling from library/node
092586df9206: Pull complete 
ef599477fae0: Pull complete 
4530c6472b5d: Pull complete 
d34d61487075: Pull complete 
87fc2710b63f: Pull complete 
e83c771c5387: Pull complete 
c28bd271641e: Pull complete 
5137e6957710: Pull complete 
1d8bcbc41a69: Pull complete 
Digest: sha256:cda22332e2dd46807a14d3268ee3fb298651386ad1f03cfd58772a7dc65f89c7
Status: Downloaded newer image for node:latest
docker.io/library/node:latest

real	0m49.463s
user	0m0.100s
sys	0m0.040s

检查加速器是否生效

执行 $ docker info,如果从结果中看到了如下内容,说明配置成功。

Registry Mirrors:
 https://dockerhub.azk8s.cn/
 https://reg-mirror.qiniu.com/
Live Restore Enabled: false

docker registry 私服搭建

无证书无密码

https://hub.docker.com/_/registry/

docker pull registry:latest  即 docker pull registry
docker run -d -p 5000:5000 -v /var/lib/registry:/var/lib/registry --restart=always --name registry  registry:2
docker tag hello-world docker.registry.server:5000/hello-world
docker push docker.registry.server:5000/hello-world
docker pull docker.registry.server:5000/hello-world

vi /etc/docker/daemon.json
{
        "registry-mirrors": ["https://9fgvz9iu.mirror.aliyuncs.com"],
        "insecure-registries": [
                "docker.registry.server:5000",
                "docker.registry.server:5000"
        ]
}

http://192.168.10.254:5000/v2/_catalog

证书+密码

服务器

服务器证书配置

cd /etc/docker
mkdir -p certs && openssl req -newkey rsa:4096 -nodes -sha256 -keyout certs/domain.key -x509 -days 365 -out certs/domain.crt
mkdir -p /etc/docker/certs.d/docker.registry.server:5000
cp certs/domain.crt /etc/docker/certs.d/docker.registry.server:5000/ca.crt

修改hosts

vi /etc/hosts
192.168.10.254 docker.registry.server

服务器配置密码

cd /etc/docker
mkdir auth && docker run --entrypoint htpasswd registry -Bbn [用户名] [密码] > auth/htpasswd

服务器使用证书和密码启动

cd /etc/docker

docker run -d -p 5000:5000 --restart=always --name registry \
-v `pwd`/auth:/auth \
-e "REGISTRY_AUTH=htpasswd" \
-e "REGISTRY_AUTH_HTPASSWD_REALM=Registry Realm" \
-e REGISTRY_AUTH_HTPASSWD_PATH=/auth/htpasswd \
-v `pwd`/registryDir:/var/lib/registry \
-v `pwd`/certs:/certs \
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/domain.crt \
-e REGISTRY_HTTP_TLS_KEY=/certs/domain.key \
registry

客户端

配置hosts

vi /etc/hosts
192.168.10.254 docker.registry.server

配置公钥

mkdir /etc/docker/certs.d/docker.registry.server:5000/
scp g@192.168.10.254:/etc/docker/certs/domain.crt .
mv domain.crt ca.crt

docker login docker.registry.server:5000

https://docker.registry.server:5000/v2/_catalog

登录 docker login -u hello -p world 192.168.10.254:5000
登出 docker logout 192.168.10.254:5000

docker trusted registry

参考
http://www.ywnds.com/?p=7411
https://www.jianshu.com/p/1a769be8f4e2

  • qq_43638135
    妲己再美究为妃: 博主没有想过自己接一些私活干吗?我现在还没毕业,但是我也确实听说外挂市场自动化游戏脚本市场挺火热的,并且报酬也很丰厚,但是具体的我也不是很清楚,求解答。 (1个月前 #47楼) 查看回复(2) 举报 回复
    22