Gitlab + Node.js 迁移到Docker记录
Centos 7.3 安装Docker
安装脚本
curl -fsSL https://get.docker.com/ | sh
启动docker
service docker start
测试是否成功
docker run hello-world
Docker + Gitlab
Gitlab为我们提供了最新版本的docker image,可以直接使用:
docker run --detach \
--hostname git.cansdk.com \
--publish 127.0.0.1:44301:443 --publish 127.0.0.1:8081:80 --publish 127.0.0.1:2201:22 \
--name gitlab \
--restart always \
--volume /home/data/gitlab/config:/etc/gitlab \
--volume /home/data/gitlab/logs:/var/log/gitlab \
--volume /home/data/gitlab/data:/var/opt/gitlab \
gitlab/gitlab-ce:latest
注意我们需要手动指定端口映射方便我们使用Nginx进行反向代理。
导入原有的git仓库
将原有的git bare复制到新gitlab的repo目录下,新建backup文件夹放进去
cp -r * /home/data/gitlab/data/git-data/repositories/bakcup/
执行命令连接docker:
docker exec -t -i docker-id /bin/bash
导入:
gitlab-rake gitlab:import:repos
手动导入bare仓库
在创建好Projects之后,执行:
git push --mirror http://git.cansdk.com/root/mycat-train.git
替换Docker源为国内源
Dockerbuild构建自定义的Node.js
以下是很偷懒的方法
首先拉一个centos 6.9的镜像下来:
docker pull registry.cn-hangzhou.aliyuncs.com/ghoulich-centos/centos-6.9-basic
然后准备好需要的Node.js包,和Node.js app,将它以bash方式启动。我这里是我自己的blog:
docker run -ti -v /home/data/blog_xiaocan:/data/blog --name xiaocan -h www.xiaocan.me 573de66f263e
此时启动成功的话会attach到container的bash中,在此进行安装和测试工作,保证它能工作。
在安装完成之后,将其打包导出:
docker commit 8dc314191abe xiaocan_ghost_blog
此时在images中就能看到了:
[root@ZJ2153 blog_xiaocan]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
xiaocan_ghost_blog latest 37e318a865ed 40 minutes ago 448MB
gitlab/gitlab-ce latest ab6138b2b7fe 4 days ago 1.31GB
centos 6.9 573de66f263e 3 months ago 195MB
最后,启动docker:
docker run -d -v /home/data/blog_xiaocan:/data/blog -p 127.0.0.1:2368:2368 --name=xiaocan_blog 37e318a865ed /bin/sh -c 'cd /data/blog && npm start --production'