Harbor和Docker-Compose 部署

部署Harbor镜像仓库

# https://blog.csdn.net/weixin_44147924/article/details/130593307
# 部署之前先安装docker和docker-compose

1. [root@local mnt]# wget https://ghproxy.com/https://github.com/goharbor/harbor/releases/download/v2.5.3/harbor-offline-installer-v2.5.3.tgz

2. [root@local mnt]# tar xf harbor-offline-installer-v2.5.3.tgz

3. [root@local mnt]# mv harbor /usr/local/bin/

4. [root@local mnt]# cd /usr/local/bin/harbor

5. [root@local harbor]# cp harbor.yml.tmpl harbor.yml

6. [root@local harbor]# vim harbor.yml
	hostname=10.0.0.88(也可以用主机名,但前提是能DNS解析出来,如果不能就写IP)
    注释https
    # https:
    # https port for harbor, default is 443
    #  port: 443
    # The path of cert and key files for nginx
    #  certificate: /your/certificate/path
    #  private_key: /your/private/key/path


7. [root@local harbor]# ./install.sh
                            
登录账号:admin
登录密码:就是harbor.yml里设置的密码harbor_admin_password: Harbor12345 
                            
# 设置http登录
1. [root@local ~]# vim /etc/docker/daemon.json     
{
  "registry-mirrors": ["https://8mh75mhz.mirror.aliyuncs.com"],
  "insecure-registries":["10.0.0.88"]
}

2. [root@local ~]# systemctl restart docker
                            
3. [root@local ~]# docker login 10.0.0.88
                            
4. [root@local ~]# docker tag 7614ae9453d1 10.0.0.88/python/redis:v1
                            
5. [root@local ~]# docker push 10.0.0.88/python/redis:v1

docker-compose部署flask

# flask 项目,使用redis服务---》2个容器
	flask 项目容器
     redis容器

新建flask项目 app.py

from flask import Flask
from redis import Redis
import os

app = Flask(__name__)
redis = Redis(host=os.environ.get('REDIS_HOST', '127.0.0.1'), port=6379)

@app.route('/')
def hello(): 
    redis.incr('hits')
    return '你好! 查看 %s 次\n' % (redis.get('hits'))


if __name__ == "__main__":
    app.run(host="0.0.0.0", port=5000, debug=True)

编写Dockerfile--》用于构建flask项目的镜像

FROM python:3.8
WORKDIR /app
COPY . /app
RUN pip install flask redis -i https://pypi.tuna.tsinghua.edu.cn/simple
EXPOSE 5000
CMD [ "python", "app.py" ]

编写docker-compose的yaml文件 docker-compose.yml

version: "3"
services:
  redis:
    image: redis
  web:
    build:
      context: .
      dockerfile: Dockerfile
    ports:
      - 8080:5000
    environment:
      REDIS_HOST: redis
          

docker-compose一键部署路飞

# 一台服务器:
	-python3.8 环境 djagno +uwsgi+代码
    -nginx软件
    -mysql 5.7
    -redis 
    
# 每个都做成一个容器
	-djagno项目容器:python3.8 构建的django,模块,uwsgi,代码
    -nginx容器:目录映射,映射到宿主机,代理vue前端,编译后的静态文件
    -mysql 容器:创建,创用户,密码,luffy库
    -redis 容器,跑起来即可
    
    
# docker-compose yml文件配置,一键启动
	-git clone https://gitee.com/liuqingzheng/luffy.git
    -目录结构
    luffy
        luffy_api  # 后台项目
        	Dockerfile
		luffycity  # 前台项目
        docker_compose_files # 放数据的文件夹
        
        docker-compose.yml #ymal文件
	-docker-compose.yml内容
	-Dockefile 文件
    - 修改前端链接后台的地址:luffycity/src/access/xx.js
    -编译:npm run build
    
    -提交到git
    
    -要部署的服务器:git clone https://gitee.com/liuqingzheng/luffy.git
    -docker,docker-compose装好
    -docker-compose up
    -访问宿主机的 80 端口

项目目录结构

luffy
	-docker_compose_files  # nginx有自己的配置文件,redis自己的配置,mysql的配置
        nginx # 文件夹
        redis # 文件夹
        mysql.env#配置文件
    -luffy_api  # 原来路飞后端项目
    	-Dockerfile
        -luffy.ini  # luffy.xml uwsgi的配置文件
    -luffycity  # 前端项目
    
    -docker-compose.yml  # docker-compose的配置文件
    

# 把luffycity/dist 文件夹删除
# 把\luffy\luffycity\src\assets\js\settings.js后端地址改成上线地址(服务器地址)
# 来到前端路径下:luffy\luffycity
cnpm install  安装依赖

# 编译,在\luffy\luffycity\dist文件夹
npm run build

# 提交到git上


# 在部署的机器上,git clone 下来
# 进入到项目目录
docker-compose up

luffy_api/Dockerfile--->构建uwsgi+django

FROM python:3.8
MAINTAINER lqz
WORKDIR /soft
COPY ./requestment.txt /soft/requestment.txt
RUN pip install -r requestment.txt -i https://pypi.doubanio.com/simple
#CMD ["uwsgi", "-x", "./luffy.xml"]
CMD ["uwsgi", "./luffy.ini"]
#CMD ["python", "manage_pro.py", "runserver"]

docker-compose.yml

version: "3"

services:
  nginx:
    image: nginx
    container_name: luffy_nginx
    ports:
      - "80:80"
      - "8000:8000"
    restart: always
    volumes:
      - ./luffycity/dist:/var/www/html
      - ./docker_compose_files/nginx:/etc/nginx/conf.d
    depends_on:
      - django
    networks:
      - web

  django:
    build:
      context: ./luffy_api
      dockerfile: Dockerfile
    container_name: luffy_django
#    command: python manage_pro.py makemigrations && python manage_pro.py migrate && uwsgi ./luffy.ini
    restart: always
    ports:
      - "8080:8080"
    volumes:
      - ./luffy_api:/soft
    environment:
      - TZ=Asia/Shanghai
    depends_on:
      - mysql
      - redis
    networks:
      - web
  redis:
    image: redis:6.0-alpine
    container_name: luffy_redis
    ports:
      - "6379:6379"
    volumes:
      - ./docker_compose_files/redis/data:/data
      - ./docker_compose_files/redis/redis.conf:/etc/redis/redis.conf
    command: redis-server /etc/redis/redis.conf
    networks:
      - web
  mysql:
    image: mysql:5.7
    container_name: luffy_mysql
    restart: always
    ports:
      - "3306:3306"
    env_file:
      - ./docker_compose_files/mysql.env
    volumes:
      - ./docker_compose_files/mysql/data:/var/lib/mysql
      - ./docker_compose_files/mysql/logs:/var/log/mysql
      - ./docker_compose_files/mysql/conf:/etc/mysql/conf.d
    networks:
      - web

networks:
  web:
posted @ 2023-08-14 20:02  秋洛尘  阅读(91)  评论(0)    收藏  举报