查资料

Docker之docker-compose

配置gitlab-ee, gitea_2024.04.30

  • docker-compose初探_2023.04.27
  • 一次写下了 vim docker-compose.yml ,填入了指令, 并且成功使用 docker-compose up 跑起来了
  • file
  • file
  • 启用nginx配置文件,尝试url跳转_2023.04.28
  • 配置gist服务_2024.4.29
  • 配置gitlab-ee _2024.04.30

实现效果

  • 1 可以通过 / 打开静态页面
  • 2 可以通过/aiur 跳转到对应页面 编辑 docker-compose.yml 文件:

$ vim docker-compose.yml

version: "3" # 表示该docker-compose.yml文件使用的是Version 3  
services:  # 为project定义服务
  nginx:  # 指定服务名称
    image: nginx  # 指定服务所使用的镜像
    ports:  # 暴露端口信息
      - 80:80
    volumes:
       - ./html:/usr/share/nginx/html
       - ./conf.d:/etc/nginx/conf.d
       - ./nginx.conf:/etc/nginx/nginx.conf
       - ./log:/var/log/nginx
    restart: always
  opengist:
    image: ghcr.io/thomiceli/opengist:1.7
    container_name: opengist
    restart: unless-stopped
    ports:
      - "6157:6157" # HTTP port
      #- "2222:2222" # SSH port, can be removed if you don't use SSH
    volumes:
      - "./opengist:/opengist"
  gitlab:
    image: gitlab/gitlab-ee:16.11.1-ee.0
    container_name: gitlab
    restart: unless-stopped
    hostname: 'gitlab.rdf.lol'
    environment:
      GITLAB_OMNIBUS_CONFIG: |
        external_url 'http://gitlab.xxx.xxx:8929'
        gitlab_rails['gitlab_shell_ssh_port'] = 2424
    ports:
      - '8929:8929'
      - '443:443'
      - '2424:2424'
    volumes:
      - './GITLAB_HOME/config:/etc/gitlab'
      - './GITLAB_HOME/logs:/var/log/gitlab'
      - './GITLAB_HOME/data:/var/opt/gitlab'
    shm_size: '256m'
  gitea:
    image: gitea/gitea:1.21.11-rootless
    restart: always
    volumes:
      - ./gitea/data:/var/lib/gitea
      - ./gitea/config:/etc/gitea
      - /etc/timezone:/etc/timezone:ro
      - /etc/localtime:/etc/localtime:ro
    ports:
      - "3000:3000"
      - "2425:2222"

  • 编辑 nginx.conf 文件

user root;
worker_processes  1;

events {
    worker_connections  2048;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  75;
	client_max_body_size 100m;

    server {
        listen       80;
        server_name  localhost;
		server_tokens off;
		
		#实现了2种处理方式,但是定义理解仍有混乱,后续细抠
		
	location ^~/aiur {
		rewrite ^/aiur/(.*)~*p https://gitlab.aiursoft.cn/explore permanent;
		rewrite ^/aiur/(.*)$  / break;
		rewrite =aiur / break;
		proxy_pass http://www.aiursoft.cn/;
	}
		
	location ^~/chat {  
			rewrite (.*) https://chat.aiursoft.cn/#/ permanent;
	}
	
	location ^~/anduin { #实现url前缀效果匹配后跳转
			rewrite ^/anduin/(.*)~*p https://gitlab.aiursoft.cn/users/anduin/projects permanent;
			rewrite =anduin / permanent;
			proxy_pass http://anduin.aiursoft.cn/;
	}
	
	location ^~/rdf { #实现url前缀效果匹配后跳转
			rewrite ^/rdf/(.*)~*p https://gitlab.rdf.lol/users/rdf/projects permanent;
			rewrite =rdf / permanent;
			proxy_pass http://rdf.aiursoft.cn/;
	}
		
	location ^~/box { #实现url前缀效果匹配后跳转
			rewrite (.*) https://gitlab.aiursoft.cn/aiursoft/box/ permanent;
	}
	
	location ^~/gist {
			rewrite (.*) https://gist.rdf.lol/ permanent;
	}
	
	location ^~/gitlab {
			rewrite ^/gitlab/(.*) https://gitlab.rdf.lol/$1 permanent;
			rewrite (.*)  http://gitlab.rdf.lol/;	 
	}
		
	location / {
			root   /usr/share/nginx/html/HD800S2;
				#root   D:/SYSI/HD800S;
			try_files $uri $uri/ /index.html;
				index  index.html index.htm;
	}
		
		        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

docker compose 开机启动

  • 根据需要进行设置
$ /etc/systemd/system/
$ vim  ./docker-compose-app.service
[Unit]
Description=Docker Compose Application Service
Requires=/snap/bin/docker-compose
After=/snap/bin/docker-compose

[Service]
Type=oneshot
RemainAfterExit=yes
WorkingDirectory=/home/rdf/Desktop
ExecStart=/snap/bin/docker-compose up -d
ExecStop=/snap/bin/docker-compose down
TimeoutStartSec=0

[Install]
WantedBy=multi-user.target

file

  • 服务拷贝(如有需要,将该服务单元文件移动到/etc/systemd/system/目录中)
sudo mv docker-compose.service /etc/systemd/system/
  • 刷新systemd服务配置:
$ sudo systemctl daemon-reload
  • 启用并启动该服务:
sudo systemctl enable docker-compose.service
sudo systemctl start docker-compose.service

当系统启动时,Docker Compose将自动启动您的应用程序容器

打印docker-compose的程序路径

which docker-compose