Docker搭建容器命令
Halo
本容器使用docker-compose搭建,通过修改 docker-compose.yaml
升级版本等操作
cd /docker-data/docker-composes/halo
docker-compose up -d # 首次运行
docker-compose start
docker-compose.yaml
version: "3"
services:
halo:
image: halohub/halo:2.10
container_name: halo
restart: on-failure:3
volumes:
- /docker-data/halo:/root/.halo2
ports:
- "8090:8090"
command:
- --spring.r2dbc.url=r2dbc:pool:mysql://192.168.1.5:3306/halo
- --spring.r2dbc.username=root
- --spring.r2dbc.password=password
- --spring.sql.init.platform=mysql
- --halo.external-url=http://127.0.0.1:8090/
- --halo.security.initializer.superadminusername=admin
- --halo.security.initializer.superadminpassword=password
# 端口号 默认8090
- --server.port=8090
Jenkins
本容器使用docker/docker-compose直接搭建
docker run \
--name=jenkins \
-u root \
--privileged=true \
-p 8800:8080 \
-p 50000:50000 \
-v /docker-data/jenkins-data:/var/jenkins_home \
-v /var/run/docker.sock:/var/run/docker.sock \
--env JENKINS_ARGS="--prefix=/jenkins" \
--env JENKINS_OPTS="--prefix=/jenkins" \
--env JAVA_OPTS="-server -Xms512m -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=512m" \
jenkinsci/blueocean:latest
docker-compose.yaml
version: "3"
services:
jenkins:
container_name: jenkins
restart: on-failure:3
image: jenkins/jenkins:2.433-jdk17
privileged: true
ports:
- 8800:8080
- 50000:50000
volumes:
- /docker-data/jenkins-data:/var/jenkins_home
- /var/run/docker.sock:/var/run/docker.sock
environment:
JENKINS_OPTS: '--prefix=/jenkins'
JAVA_OPTS: '-Duser.timezone=Asia/Shanghai -server -Xmn256m -Xms512m -Xmx512m'
JENKINS_ARGS: '--prefix=/jenkins'
JENKINS_PREFIX: '/jenkins'
使用https://domain.com:18443/jenkins/ 访问 nginx
配置如下
# jenkins
location /jenkins {
proxy_pass http://127.0.0.1:8800;
# Rewrite HTTPS requests from WAN to HTTP requests on LAN
proxy_redirect http:// https://;
# The following settings from https://wiki.jenkins-ci.org/display/JENKINS/Running+Hudson+behind+Nginx
sendfile off;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Host $host:$server_port;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_max_temp_file_size 0;
# This is the maximum upload size
client_max_body_size 10m;
client_body_buffer_size 128k;
proxy_connect_timeout 90;
proxy_send_timeout 90;
proxy_read_timeout 90;
proxy_temp_file_write_size 64k;
# Required for new HTTP-based CLI
proxy_http_version 1.1;
proxy_request_buffering off;
proxy_buffering off; # Required for HTTP-based CLI to work over SSL
}
GitLab
本容器使用docker直接搭建
docker run \
-itd \
--hostname hostname \
--publish 10000:22 \
--publish 10100:80 \
--publish 10200:443 \
--name gitlab-ce \
--restart always \
--privileged=true \
--volume /docker-data/gitlab/config:/etc/gitlab \
--volume /docker-data/gitlab/logs:/var/log/gitlab \
--volume /docker-data/gitlab/data:/var/opt/gitlab \
gitlab-ce:16.2.3
docker-compose.yaml
version: "3.6"
services:
gitlab:
image: gitlab/gitlab-ce:16.11.8-ce.0
container_name: gitlab-ce
restart: on-failure:3
ports:
- '10000:22'
- '10100:80'
- '10200:443'
volumes:
- /docker-data/gitlab/config:/etc/gitlab
- /docker-data/gitlab/logs:/var/log/gitlab
- /docker-data/gitlab/data:/var/opt/gitlab
privileged: true
hostname: www.youcats.cn
network_mode: bridge
environment:
- GITLAB_SKIP_UNMIGRATED_DATA_CHECK=true
Nginx
本容器使用docker直接搭建
docker run \
-d \
--name=nginx-upload-2 \
--privileged=true \
-v /docker-data/image-upload/conf:/etc/nginx/conf.d \
-v /docker-data/image-upload/www:/usr/share/nginx \
-p 20200:80 \
-p 20300:443 \
nginx:alpine
Portainer
本容器使用docker直接搭建
docker run \
-d \
-p 9000:9000 \
--name portainer-ce \
--restart=always \
--privileged=true \
-v /var/run/docker.sock:/var/run/docker.sock \
-v /disk/portainer/data:/data \
-v /disk/portainer/public:/public \
portainer-ce:2.18.3
Redis
本容器使用docker直接搭建,Redis版本和配置需要一致
docker run \
--privileged=true \
--restart=always \
--name=Redis5 \
-p 6385:6379 \
-v /docker-data/redis5/redis.conf:/etc/redis/redis.conf \
-v /docker-data/redis5/data:/data \
-d redis:6.0.16 \
redis-server \
/etc/redis/redis.conf
docker-compose.yaml
version: '3'
services:
jellyfin:
image: portainer/portainer-ce:2.21.0
container_name: portainer-ce
restart: on-failure:3
privileged: true
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /disk/portainer/data:/data
- /disk/portainer/public:/public
ports:
- 9000:9000
MySQL
本容器使用docker直接搭建
SHOW VARIABLES LIKE 'character%'; #查字符集
docker run \
-d -p 3310:3306 \
-p 33100:33060 \
-e MYSQL_ROOT_PASSWORD=******918 \
-e TZ=Asia/Shanghai \
--name=MySQL \
--privileged=true \
-v /docker-data/mysql/log:/var/log/mysql \
-v /docker-data/mysql/data:/var/lib/mysql \
-v /docker-data/mysql/conf:/etc/mysql/conf.d \
mysql:8.0.27 #开启挂载等数据目录
问题:ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
解决方法:docker中运行以下命令 https://zhuanlan.zhihu.com/p/589283782
usermod -d /var/lib/mysql/ mysql
ln -s /var/lib/mysql/mysql.sock /tmp/mysql.sock
chown -R mysql:mysql /var/lib/mysql
service mysql restart #重启容器
或者:mysql -h 127.0.0.1 -u root -p
[mysqld]
log-bin=mysql-bin
binlog_format=mixed
server-id=1
binlog-ignore-db=mysql,sys,performance_schema,information_schema
flush tables with read lock; // 全局锁,禁止写入,只允许读取
SET SQL_LOG_BIN=0;
CREATE USER slaveuser@'%' IDENTIFIED WITH mysql_native_password BY 'password';
grant replication slave on *.* to slaveuser@'%';
flush privileges;
SET SQL_LOG_BIN=1;
show master status
unlock tables;
[mysqld]
log-bin=mysql-bin
binlog_format=mixed
server-id=2
replicate-ignore-db=mysql,sys,performance_schema,information_schema
log-slave-updates
slave-skip-errors=all
stop slave
reset slave
change master to master_host='192.168.1.2',master_port=3306,master_user='SLAVE_1',master_password='hhhhhhh0918_@!',master_log_file='mysql-bin.000004',master_log_pos=52325;
start slave
show slave status
SET GLOBAL server-id=102
SHOW VARIABLES LIKE 'server_id';
mysqldump -u root -p --databases BONUS_CALCULATION BookKeeping BookRegistration cloudreve halo ImageUpload nextcloud nginxwebui WhatEatToday YouGos YouGosNews --single-transaction --source-data=2 --flush-logs > /tmp/mysqlbackup/`date +%F_%H-%M-%S`-mysql-all.sql
scp 2023-12-26_14-12-07-mysql-all.sql *.*.84.182:/tmp/
mysql -u root -p < /tmp/2023-12-26_14-12-07-mysql-all.sql
change master to master_host='*.*.84.182',master_port=3306,master_user='SLAVE_2',master_password='*****0918_@!',master_log_file='mysql-bin.000274',master_log_pos=157;
Mysqld-exporter
下载mysqld_exporter-0.15.1.linux-amd64.tar.gz
解压然后运行
配置如下,在Prometheus中监听
[client]
# 第一个 MySQL 数据库实例
host = localhost
port = 3306
user = root
password = ******
守护进程(mysqld_exporter.service)如下
[Unit]
Description=mysqld_exporter
After=network.target
[Service]
ExecStart=/opt/mysqld_exporter/mysqld_exporter --config.my-cnf=/opt/mysqld_exporter/my.cnf
Restart=on-failure
[Install]
WantedBy=multi-user.target
Harbor
本容器使用docker-compose搭建,创建在docker内部ubuntu容器内
cd /disk/ubuntu/opt/harbor
docker-compose start
harbor.yml
# Configuration file of Harbor
# The IP address or hostname to access admin UI and registry service.
# DO NOT use localhost or 127.0.0.1, because Harbor needs to be accessed by external clients.
hostname: hostname
# http related config
# http:
# port for http, default is 80. If https enabled, this port will redirect to https port
# port: 5050
# https related config
https:
# https port for harbor, default is 443
port: 5050
# The path of cert and key files for nginx
certificate: /opt/harbor/https/ca/youcats.cn_bundle.pem
private_key: /opt/harbor/https/ca/youcats.cn.key
Jellyfin
version: '3'
services:
jellyfin:
image: jellyfin/jellyfin:latest
container_name: jellyfin
restart: on-failure:3
privileged: true
volumes:
- /disk/jellyfin:/media
ports:
- 8096:8096
Prometheus
version: "3"
services:
prometheus:
image: bitnami/prometheus:2.48.1
container_name: prometheus
restart: on-failure:3
volumes:
- /docker-data/prometheus/config/prometheus.yml:/etc/prometheus/prometheus.yml
- /docker-data/prometheus/data:/prometheus
ports:
- "9090:9090"
privileged: true
network_mode: bridge
user: root
prometheus.yml
global:
scrape_interval: 15s
evaluation_interval: 15s
scrape_configs:
- job_name: 'prometheus'
scrape_interval: 5s
static_configs:
- targets: ['localhost:9090']
Grafana
version: "3"
services:
grafana:
image: grafana/grafana:10.0.10
container_name: grafana
restart: on-failure:3
ports:
- "3000:3000"
privileged: true
network_mode: bridge
Dpanel
version: "3"
services:
dpanel:
image: dpanel/dpanel:1.0.4.2-lite
container_name: dpanel
restart: on-failure:3
ports:
- 8080:8080
environment:
APP_NAME: dpanel # 请保持此名称与 container_name 一致
INSTALL_USERNAME: admin
INSTALL_PASSWORD: admin
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- /disk/dpanel:/dpanel