1.基础配置:
主机名 | IP | 系统版本 |
---|
k8s-master | 192.168.32.128 | centos 7.6 |
k8s-node1 | 192.168.32.129 | centos 7.6 |
k8s-node2 | 192.168.32.130 | centos 7.6 |
k8s-harbor | 192.168.32.131 | centos 7.6 |
2.安装docker-compose
curl -L https://get.daocloud.io/docker/compose/releases/download/1.25.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
$ docker-compose -version
docker-compose version 1.25.0, build 0a186604
3.下载Harbor的压缩包
https://github.com/goharbor/harbor/releases
tar -xzf harbor-offline-installer-v2.1.0_2.tgz
mkdir /opt/harbor
mv harbor/* /opt/harbor
cd /opt/harbor
4.修改harbor配置
cp -a harbor.yml.tmpl harbor.yml
vim harbor.yml
修改hostname和port
hostname: 172.21.3.23
port: 80
5.安装harbor
./install.sh
6.启动、停止、重启
docker-compose up -d 启动
docker-compose stop 停止
docker-compose restart 重新启动
7.访问harbor
http://192.168.32.131
默认账户密码:admin/Harbor12345
8.配置仓库
[root@k8s-harbor harbor]
{
"insecure-registries": ["192.168.32.131"]
}
9.登录仓库
[root@k8s-n1 harbor]# docker login 192.168.32.131
Username: admin
Password:
WARNING! Your password will be stored unencrypted in /root/.docker/config.json.
Configure a credential helper to remove this warning. See
https://docs.docker.com/engine/reference/commandline/login/#credentials-store
Login Succeeded
10.编写Dockerfile nginx
FROM centos:7.2.1511
VOLUME /tmp
MAINTAINER Harry
ADD nginx-1.18.0.tar.gz /usr/src/
RUN useradd -r -s /sbin/nologin nginx
RUN yum install -y gcc pcre-devel openssl-devel zlib-devel make
ENV NGINX_DIR /usr/src/nginx-1.18.0
WORKDIR $NGINX_DIR
RUN ./configure --prefix=/usr/local/nginx \
--user=nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module
RUN pwd
RUN make && make install
RUN ln -s /usr/local/nginx/sbin/nginx /usr/sbin/nginx
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
11.执行Dockerfile
docker build -f Dockerfile -t nginx . >/dev/null 2>&1
12.上传镜像到私有仓库
12.1 给nginx:latest修改标记为192.168.32.131/nginx/nginx:22401
docker tag nginx:latest 192.168.32.131/nginx/nginx:22401
12.2推送镜像到192.168.32.131/nginx/nginx:22401
docker push 192.168.32.131/nginx/nginx:22401
启动docker例子:
-p: 9090(外部映射端口) 80(容器内部监控端口)
-d: 后台运行
docker run -id -d -p 9090:80 --name testnginx -v /usr/local/nginx/conf/nginx.conf:/usr/local/nginx/conf/nginx.conf 192.168.32.131/nginx/nginx:22401
进入镜像:
docker exec -it 镜像名 /bin/bash
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)