03-habor仓库
2019-12-09 本文已影响0人
UncleZ_strive
1,镜像的分层与dockerfile的优化
镜像分层的好处:复用,节省磁盘空间,相同的内容只需加载一份到内存。 修改dockerfile之后,再次构建速度快
dockerfile 优化:
1:尽可能选择体积小linux发行版,alpine
2:尽可能合并RUN指令,清理无用的文件(yum缓存,源码包)
3:修改dockerfile,把变化的内容尽可能放在dockerfile结尾
4: 使用.dockerignore,减少不必要的文件ADD . /html
[root@docker01 ~]# cat dockerfile/wordpress/dockerfile
FROM centos6.9_nginx:v1
RUN echo "192.168.37.200 mirrors.aliyun.com" >>/etc/hosts && \
curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-6.repo && \
curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-6.repo && \
yum install nginx php-fpm php-gd php-mbstring unzip php-mysql -y && \
yum clean all
ADD www.conf /etc/php-fpm.d/www.conf
RUN rm -f /etc/nginx/conf.d/*
ADD wordpress.conf /etc/nginx/conf.d/kod.conf
ADD init.sh /init.sh
RUN mkdir /html && cd /html
ADD wordpress.tar.gz /html
RUN chown -R nginx:nginx /html
EXPOSE 80
CMD ["/bin/bash","/init.sh"]
2.docker-compose(单机版的容器编排工具)
ansible剧本 yml
yum install -y docker-compose(需要epel源)
cd my_wordpress/ vi docker-compose.yml
[root@docker01 ~]# cat /zabbix/docker-compose.yml
version: '3'
services:
mysql-server:
image: mysql:5.7
restart: always
command: --character-set-server=utf8 --collation-server=utf8_bin
environment:
MYSQL_ROOT_PASSWORD: root_pwd
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix_pwd
zabbix-java-gateway:
image: zabbix/zabbix-java-gateway:latest
restart: always
zabbix-server:
depends_on:
- mysql-server
- zabbix-java-gateway
image: zabbix/zabbix-server-mysql:latest
ports:
- "10051:10051"
restart: always
environment:
DB_SERVER_HOST: mysql-server
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix_pwd
MYSQL_ROOT_PASSWORD: root_pwd
ZBX_JAVAGATEWAY: zabbix-java-gateway
zabbix-web:
depends_on:
- mysql-server
- zabbix-server
image: zabbix/zabbix-web-nginx-mysql:latest
ports:
- "80:80"
restart: always
environment:
DB_SERVER_HOST: mysql-server
MYSQL_DATABASE: zabbix
MYSQL_USER: zabbix
MYSQL_PASSWORD: zabbix_pwd
MYSQL_ROOT_PASSWORD: root_pwd
3.docker registry(私有仓库)
-
普通的registry
docker run -d -p 5000:5000 --restart=always --name registry -v /opt/myregistry:/var/lib/registry registry
1.上传镜像到私有仓库:
a:给镜像打标签 docker tag centos6-sshd:v3 10.0.0.11:5000/centos6-sshd:v3
b:上传镜像 docker push 10.0.0.11:5000/centos6-sshd:v3
2.如果遇到报错:
The push refers to repository [10.0.0.11:5000/centos6.9_ssh] Get [https://10.0.0.11:5000/v2/](https://10.0.0.11:5000/v2/): http: server gave HTTP response to HTTPS client
编写配置文件可解决
vim /etc/docker/daemon.json
{
"insecure-registries": ["10.0.0.11:5000"]
}
systemctl restart docker
22:docker企业级镜像仓库harbor(vmware 中国团队)
- http模式
第一步:安装docker和docker-compose
第二步:下载harbor镜像 harbor-offline-installer-v1.5.1.tgz
第三步:上传到/opt,并解压
第四步:修改harbor.cfg配置文件 harbor.yml
hostname = 10.0.0.11
harbor_admin_password = 123456
第五步:执行./install.sh
- harbor配置https:
修改配置文件harbor.yml
hostname: s.zhanghail.cn
https:
port: 443
ui_url_protocol = https
certificate: /root/hhh/cert/2859609_s.zhanghail.cn.pem
private_key: /root/hhh/cert/2859609_s.zhanghail.cn.key
-
registry私有仓库迁移至habor
1.新建项目
image.png
2.仓库管理-----新建目标
image.png
3.同步管理-----新建规则
image.png