1.创建普通的镜像仓库
docker run -d -p 5000:5000 --restart=always --name registry -v
/opt/myregistry:/var/lib/registry registry
--restart=always 只要docker启动,该容器就会启动
2.修改配置文件,使之支持http
cat /etc/docker/daemon.json
{
"registry-mirrors": ["https://registry.docker-cn.com"],
"insecure-registries": ["10.0.0.100:5000"]
}
systemctl restart docker
3.修改镜像标签
docker tag busybox:latest 10.0.0.100:5000/clsn/busybox:1.0
4.将新打标签的镜像上传镜像到仓库
[root@docker01 ~]# docker push 10.0.0.100:5000/clsn/busybox
5.将新的镜像拉取下来(拉取需要带版本)
docker pull 10.0.0.100:5000/clsn/busybox:1.0
6.查看仓库镜像
curl 10.0.0.100:5000/v2/_catalog
封装镜像时使用目录,即为在封装时创建目录
企业级镜像仓库Harbor
#下载harbor
cd /opt/harbor && wget https://storage.googleapis.com/harbor-releases/harbor-offline-installer-v1.6.1.tgz
tar xf harbor-offline-installer-v1.6.1.tgz
# 快速安装compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.1/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
修改主机名及web界面密码
[root@docker01 harbor]# vim harbor.cfg
···
hostname = 192.168.1.2
harbor_admin_password = Harbor12345
···
./install.sh
http://192.168.1.2
在界面里添加项目
在本地
vim /etc/docker/daemon.json
添加"insecure-registries": ["https://192.168.1.2"]
docker login 192.168.1.2
docker push 192.168.1.2/test/busybox:v1
docker-compose
# 快速安装 docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.24.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose
开启pip下载加速器
mkdir ~/.pip/
cat > ~/.pip/pip.conf <<'EOF'
[global]
index-url = https://mirrors.aliyun.com/pypi/simple/
[install]
trusted-host=mirrors.aliyun.com
EOF
编写编排文件(让脚本自动拉取镜像,自己拉取反而会报错)
version: '2'
services:
db:
image: mysql:5.7
volumes:
- /data/db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- /data/web_data:/var/www/html
ports:
- "80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
启动两台wordpress
docker-compose scale db=1 wordpress=2
修改配置文件
vim /etc/haproxy/haproxy.cfg
global
log 127.0.0.1 local2
chroot /var/lib/haproxy
pidfile /var/run/haproxy.pid
maxconn 4000
user haproxy
group haproxy
daemon
stats socket /var/lib/haproxy/stats level admin #支持命令行控制
defaults
mode http
log global
option httplog
option dontlognull
option http-server-close
option forwardfor except 127.0.0.0/8
option redispatch
retries 3
timeout http-request 10s
timeout queue 1m
timeout connect 10s
timeout client 1m
timeout server 1m
timeout http-keep-alive 10s
timeout check 10s
maxconn 3000
listen stats
mode http
bind 0.0.0.0:8888
stats enable
stats uri /haproxy-status
stats auth admin:123456
frontend frontend_www_example_com
bind 10.0.122.147:8000
mode http
option httplog
log global
default_backend backend_www_example_com
backend backend_www_example_com
option forwardfor header X-REAL-IP
option httpchk HEAD / HTTP/1.0
balance roundrobin
server web-node1 10.0.122.147:32769 check inter 2000 rise 6 fall 4
server web-node2 10.0.122.147:32770 check inter 2000 rise 6 fall 4
启动haproxy'
systemctl start haproxy
添加php页面
vim /data/web_data
<html>
<head>
<title>PHP测试</title>
</head>
<body>
<?php echo '<p>Hello World </p>'; ?>
<?php echo "访问的服务器地址是:"."<fontcolor=red>"._SERVER['SERVER_NAME']."</font>"."
";
8000端口为用户访问
8888端口为监控端口
安装socket控制haproxy
yum install socat.x86_64 -y
节点下线
echo "disable server backend_www_example_com/web-node2"|socat stdio /var/lib/haproxy/stats
节点上线
echo "enable server backend_www_example_com/web-node1"|socat stdio /var/lib/haproxy/stats
网友评论