<ul class="nav nav-tabs " role="tablist">
<li role="presentation" id="tasks" class="">
<a href="/my/course/5">
目录
</a>
</li>
<li role="presentation" id="threads" class="active">
<a href="/my/course/5/threads">
话题
<small>(191)</small>
</a>
</li>
<li role="presentation" id="notes" class="">
<a href="/my/course/5/notes">
笔记
<small>(137)</small>
</a>
</li>
<li role="presentation" id="material" class="">
<a href="/my/course/5/material">
资料区
<small>(2)</small>
</a>
</li>
<li role="presentation" id="reviews" class="">
<a href="/my/course/5/reviews">
评价
<small>(33)</small>
</a>
</li>
<li role="presentation" id="summary" class="">
<a href="/my/course/5/summary">
介绍
</a>
</li>
<li class="highlight" style="left: 92px; 128px; overflow: hidden;"></li></ul>
</div>
- 讨论区
- 话题
<h2 class="thread-title">
win10专业版Hyper-v下Docker挂载volume的方式使用Gitlab(汉化版)保存资料数据(使用外部redis)
</h2>
<div class="thread-metas">
By <a class="link-dark link-primary" href="/user/320">五行缺猫</a>
<span class="bullet mhs">•</span>
2018-02-21
<span class="bullet mhs">•</span>
917次浏览
</div>
</div>
<div class="thread-body"><p>因为我打算使用公用的redis,所以先创建一个redis镜像</p>
首先创建一个docker目录(以下以G盘为例)
在docker目录下创建redis目录
在redis目录下添加文件docker-compose.yml文件,内容为:
(2018年4月11日修改volumes下面的挂载volume不使用/g/docker/redis/xxx方式,在最新版docker中已不能使用,改为docker-compose.yml的相对路径./redis/conf来挂载)
version: '3'
services:
redis:
image: redis:4.0.8-alpine
container_name: db-redis
restart: always
ports:
- 6379:6379
networks:
- net_db
volumes:
- ./redis/config:/docker/config
- ./redis/data:/data
command: redis-server /docker/config/redis.conf
networks:
net_db:
external: true
在redis目录下添加config目录
在config目录下添加redis.conf文件,内容为:
#redis的databases数量
databases 32
#redis密码
requirepass 123
回到redis目录,打开vscode、powershell或者cmd
首先创建一个network,然后执行docker-compose -d up
PS G:docker
edis> docker network create net_db
0583088e9269e9d1e7029682f409690547ae9325b0aee795b3d76676b7409abc
PS G:docker
edis> docker-compose up -d
Creating db-redis ... done
PS G:docker
edis> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b0b552dc45fa redis:4.0.8-alpine "docker-entrypoint.s…" 38 seconds ago Up 35 seconds 0.0.0.0:6379->6379/tcp db-redis
启动成功,用客户端连接测试localhost:6379@123(密码)连接正常
接下来开始启动Gitlab
在docker目录下创建gitlab目录
在其中创建docker-compose.yml文件,内容为:
version: '3'
services:
gitlab:
image: 'twang2218/gitlab-ce-zh:10.4.3'
container_name: gitlab-1043
restart: unless-stopped
environment:
TZ: 'Asia/Shanghai'
GITLAB_OMNIBUS_CONFIG: |
external_url 'http://gitlab-1043'
gitlab_rails['time_zone'] = 'Asia/Shanghai'
#以下为启用邮件相关设置,我用的是阿里云免费企业邮箱
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = 'smtp.mxhichina.com'
gitlab_rails['smtp_port'] = 465
gitlab_rails['smtp_user_name'] = '我的阿里云企业邮箱账号'
gitlab_rails['smtp_password'] = '我的阿里云企业邮箱密码'
gitlab_rails['smtp_domain'] = '我的阿里云企业邮箱域名'
gitlab_rails['smtp_authentication'] = 'plain'
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['smtp_tls'] = true
gitlab_rails['gitlab_email_from'] = '收到邮件时显示的发送邮箱'
user["git_user_email"] = '用户邮箱地址,跟上一条一样'
#修改sidekiq的数量,减少内存占用,默认为15,也可以不填
sidekiq['concurrency'] = 10
#使用外部redis所需设置,根据刚刚生成的redis设置修改
gitlab_rails['redis_port'] = 6379
gitlab_rails['redis_host'] = 'db-redis'
gitlab_rails['redis_password'] = '123'
gitlab_rails['redis_database'] = '1'
#因为22端口被占用,修改映射的端口号时,同时修改在Gitlab项目中的ssh地址加上端口号
gitlab_rails['gitlab_shell_ssh_port'] = 10022
ports:
- '10080:80'
- '10443:443'
- '10022:22'
networks:
- net_db
volumes:
- ./config:/etc/gitlab
- gitlab-data:/var/opt/gitlab
- ./logs:/var/log/gitlab
volumes:
gitlab-data:
external: true
networks:
net_db:
external: true
在Docker内部创建一个volume,然后执行docker-compose -d up
PS G:dockergitlab> docker volume create gitlab-data
gitlab-data
PS G:dockergitlab> docker-compose up -d
Creating gitlab-1043 ... done
PS G:dockergitlab> docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
c7cba6a06740 twang2218/gitlab-ce-zh:10.4.3 "/assets/wrapper" 29 seconds ago Up 24 seconds (health: starting) 0.0.0.0:10022->22/tcp, 0.0.0.0:10080->80/tcp, 0.0.0.0:10443->443/tcp gitlab-1043
b0b552dc45fa redis:4.0.8-alpine "docker-entrypoint.s…" 14 minutes ago Up 14 minutes 0.0.0.0:6379->6379/tcp
db-redis
等待Gitlab自己生成配置完成以后,就可以访问http://localhost:10080访问gitlab了
可以在等待时输入docker logs -f gitlab-1043跟踪gitlab的生成状态
如果需要备份出来gitlab-data的数据,可以创建一个临时的镜像方式把文件copy出来
PS G:docker> docker run --name data -v /g/docker/backup:/backup -v gitlab-data:/data ubuntu:17.10 cp -r /data/ /backup/
cp: cannot create special file '/backup/data/postgresql/.s.PGSQL.5432': Operation not permitted
cp: cannot create special file '/backup/data/redis/redis.socket': Operation not permitted
cp: cannot create special file '/backup/data/gitlab-rails/sockets/gitlab.socket': Operation not permitted
cp: cannot create special file '/backup/data/gitlab-workhorse/socket': Operation not permitted
cp: cannot create special file '/backup/data/gitaly/gitaly.socket': Operation not permitted
PS G:docker> docker rm data
data
上面这几个无法copy的文件就是导致不能使用volume直接挂载在windows目录下的原因,其他文件都可以正常备份和修改
</div>
<h3 class="thread-posts-heading">
<span class="glyphicon glyphicon-share-alt"></span>
<span id="thread-post-num">8</span> 回复 </h3>
<ul class="thread-post-list media-list">
<li id="post-155" name="post-155" class="thread-post media clearfix">
<a class="pull-left media-object js-user-card" href="/user/320" data-card-url="/user/320/card/show" data-user-id="320">
<img class="avatar-sm" src="/files/user/2017/11-19/18571178ed01393852.jpg">
mysql也可以用同样的方式挂载在Docker的volume中
先创建一个mysql-data volume
PS G:docker> docker volume create mysql-data
mysql-data
然后创建一个mysql
(2018年4月11日修改volumes挂载方式/g/docker/mysql/xxxx为./mysql/xxx的方式,因最新版docker已不支持/g/的绝对路径表达方式,改为./的相对路径【以docker-compose.yml的相对路径】)
version: '3'
services:
db:
image: mysql/mysql-server:5.7.21
container_name: db-mysql
restart: always
command: mysqld --character-set-server=utf8 --collation-server=utf8_general_ci
ports:
- 3306:3306
networks:
- net_db
environment:
MYSQL_ROOT_PASSWORD: pwd123456
volumes:
- ./mysql/mysql-init:/docker-entrypoint-initdb.d
- mysql-data:/var/lib/mysql
volumes:
mysql-data:
external: true
networks:
net_db:
external: true
同样只要不手动删除mysql-data这个volume,数据就不会丢失
gitlab的汉化镜像更新到10.5.1了,只需要把docker-compose.yml中的twang2218/gitlab-ce-zh:10.4.3改为twang2218/gitlab-ce-zh:10.5.1,container_name: gitlab-1043也可以修改为container_name: gitlab-1051(改不改没事不影响正常使用,就是方便区分版本)
然后重新执行一遍docker-compose up -d就会自动升级到10.5.1版本了,需要重新执行一遍配置流程,过程长短看机器性能而定,可以通过docker logs -f --tail 20 gitlab-1051(没改过名字就还是gitlab-1043)监控配置是否完成,并且之前Gitlab中的数据不会丢失。
<h3 class="thread-posts-heading"><span class="glyphicon glyphicon-plus"></span> 添加回复</h3>
<form id="thread-post-form" class="form-vertical" method="post" action="/course/5/thread/100/post" data-auto-submit="false" novalidate="novalidate">
</section>
node.js---sails项目开发(2)
基于 phantomjs 的自动化测试---(1)
node.js---sails项目开发(1)
mongoose基于mongodb的数据评论设计
js复杂数据格式提交
[LeetCode]Rotate Image
[LeetCode]Minimum Path Sum
[LeetCode]Generate Parentheses
[LeetCode]Gray Code