赞
踩
我们开发的时候难免会使用到各种服务型的软件,以软件的方式安装后有以下的缺点:
1,不方便卸载,也容易有残留导致下一次安装的时候有问题
2, 不能启动多个相同服务,比如:本地运行了两个项目,都需要用到redis多开就比较麻烦
3, 也比较占后台,不能随时暂停或者启动,导致电脑游戏的时候也在“工作”,非常不专心
因此,我强烈推荐docker
演示:
配置好docker后就只需以下几步即可开启一个服务,我以常用的mysql为列子:
- version: '2.0'
- services:
- mysql:
- image: mysql
- restart: always
- container_name: mysql
- environment:
- MYSQL_ROOT_PASSWORD: 2332636023
- command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 --max_allowed_packet=128M
- ports:
- - 3306:3306
- volumes:
- - ./data:/var/lib/mysql
- # - /etc/localtime:/etc/localtime:ro
docker-compose up -d
第一次启动会有点慢,需要下载容器(相当于安装包),这些都不用管了,慢慢等待就可以了,后面配置的时候会讲怎么让下载速度不受除自己网络带宽以外的其它限制
点击view detail
如果和直接装sql相比,容易懂很多,mysql直接装会有好多服务,我直接不能具体了解它的资源占用
既然如此方便,那我接下来就演示一下怎么安装和配置docker desktop
官网链接: Install Docker Desktop on Windows | Docker Documentation
根据自己需求下载相应的版本,因为我只有windows系统电脑,就演示这个了
下载后还是尽量以管理员省份安装不然可能会报错,比如我的以用户身份安装就出现了一些奇奇怪怪的错误,我还以为是没卸载干净!!!
(1)键盘输入ctrl + shift + esc 打开任务管理器,查看自己是否开启虚拟化
若开启了就可以跳过这个步骤
(2)开启虚拟化
具体参考此博客
(26条消息) Windows开启 CPU 虚拟化 + 关闭 Hyper-V_关闭cpu虚拟化_想你依然心痛的博客-CSDN博客
(1)win+r 输入control
(2)重启电脑,就可以安装docker了,尽量以管理员身份运行
1. 全选最好!不然很多容器运行可能有问题
(后续补图)
然后全选的话需要下载wsl才能使用,不然会报错
(后续补)
2.wsl下载链接
官网下载方法:安装 WSL | Microsoft Learn
然后我在一些电脑上发现各种奇奇怪怪的错误,非常让人不想继续了,所以给大家一个最终须要下载的安装包。
某盘地址:链接: https://pan.baidu.com/s/1FufvWwjyLJgY6XfuciCg9g 提取码: d9ks
(这个大小16M,直接安装就不会报错了)
(1)打开设置
或者
注意上一行的逗号别漏了哦~
- "registry-mirrors": [
- "https://registry.docker-cn.com",
- "http://hub-mirror.c.163.com",
- "https://docker.mirrors.ustc.edu.cn"
- ]
- version: '2.0'
- services:
- mysql:
- image: mysql
- restart: always
- container_name: mysql
- environment:
- # mysql 密码,账号为root
- MYSQL_ROOT_PASSWORD: 2332636023
- command: --default-authentication-plugin=mysql_native_password --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --explicit_defaults_for_timestamp=true --lower_case_table_names=1 --max_allowed_packet=128M
- ports:
- - 3306:3306
- volumes:
- - ./data2:/var/lib/mysql
- # - /etc/localtime:/etc/localtime:ro
- version: "2"
- services:
- redis:
- image: redis
- hostname: redis
- container_name: redis
- restart: always
- ports:
- # 端口映射
- - '6379:6379'
- volumes:
- # 目录映射
- - './config-docker/redis/redis.conf:/usr/local/etc/redis/redis.conf'
- - './DBdata/redis:/data'
- # 在容器中执行的命令
- command: redis-server /usr/local/etc/redis/redis.conf
- version: '1.0'
-
- services:
- mongo:
- image: mongo
- container_name: mongo1
- restart: always
- # command: --config /etc/mongo/mongod.conf
- ports:
- - 27017:27017
- volumes:
- # 挂载数据目录
- - ./db:/data/db
- # 挂载日志目录
- - ./log:/var/log/mongodb
- # 挂载配置目录
- - ./config:/etc/mongo
- version: "3"
- services:
- gitlab:
- restart: always
- image: gitlab/gitlab-ce:14.0.5-ce.0
- container_name: gitlab
- hostname: localhost
- ports:
- - "80:80"
- - "8022:22"
- - "8443:443"
- - "5432:5432"
- volumes:
- - ./config:/etc/gitlab
- - ./data:/var/opt/gitlab
- environment:
- TZ: Asia/Shanghai
- GITLAB_OMNIBUS_CONFIG: |
- # 配置克隆时的url地址,一般配置为本地的ip,这样局域网中的都可以用,如果自己的ip经常变,还是建议配置为http://localhost,只给自己使用,然后复制克隆地址的时候自己改localhost为主机当前ip
- external_url 'http://10.88.10.21'
- gitlab_rails['time_zone'] = 'Asia/Shanghai'
-
- # 关闭电子邮件相关功能
- gitlab_rails['smtp_enable'] = false
- gitlab_rails['gitlab_email_enabled'] = false
- gitlab_rails['incoming_email_enabled'] = false
-
- # Terraform
- gitlab_rails['terraform_state_enabled'] = false
-
- # Usage Statistics
- gitlab_rails['usage_ping_enabled'] = false
- gitlab_rails['sentry_enabled'] = false
- grafana['reporting_enabled'] = false
-
- # 关闭容器仓库功能
- gitlab_rails['gitlab_default_projects_features_container_registry'] = false
- gitlab_rails['registry_enabled'] = false
- registry['enable'] = false
- registry_nginx['enable'] = false
-
- # 包仓库
- gitlab_rails['packages_enabled'] = false
- gitlab_rails['dependency_proxy_enabled'] = false
-
- # GitLab KAS
- gitlab_kas['enable'] = false
- gitlab_rails['gitlab_kas_enabled'] = false
-
- # Mattermost
- mattermost['enable'] = false
- mattermost_nginx['enable'] = false
-
- # Kerberos
- gitlab_rails['kerberos_enabled'] = false
- sentinel['enable'] = false
-
- # GitLab Pages
- gitlab_pages['enable'] = false
- pages_nginx['enable'] = false
-
- # 禁用 PUMA 集群模式
- puma['worker_processes'] = 0
- puma['min_threads'] = 1
- puma['max_threads'] = 2
-
- # 降低后台守护进程并发数
- sidekiq['max_concurrency'] = 5
-
- gitlab_ci['gitlab_ci_all_broken_builds'] = false
- gitlab_ci['gitlab_ci_add_pusher'] = false
-
- # 关闭监控
- prometheus_monitoring['enable'] = false
- alertmanager['enable'] = false
- node_exporter['enable'] = false
- redis_exporter['enable'] = false
- postgres_exporter['enable'] = false
- pgbouncer_exporter['enable'] = false
- gitlab_exporter['enable'] = false
- grafana['enable'] = false
- sidekiq['metrics_enabled'] = false
- version: '1.1'
- services:
- mariadb:
- image: mariadb:10.5.17
- container_name: "mariadb1"
- restart: always
- environment:
- # 创建一个noal用户
- MYSQL_USER: "noal"
- # noal用户密码为 2332636023
- MYSQL_PASSWORD: "2332636023"
- # root用户默认就会有,root用户密码为 2332636023
- MYSQL_ROOT_PASSWORD: "2332636023"
- TZ: "Asia/Shanghai"
- ports:
- - "3306:3306"
- volumes:
- - ./data:/var/lib/mysql
- - ./log:/var/log/mysql
- - ./conf:/etc/mysql
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。