GitLab
- 新建 myshop 项目
- 使用 ssh 克隆到本地
- 将代码复制进 myshop
- 提交到本地仓库
- 提交到远程仓库
从 GitLab 拉取源代码到 Docker 容器中
- 生成 SSH KEY
ssh-keygen -t rsa -C "1225459207@qq.com"
执行成功后的效果:
root@ubuntu:/usr/local# ssh-keygen -t rsa -C "1225459207@qq.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Created directory '/root/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:SNSUCY8K6uGvALnQjKzbVuGSjLxssXC01uFdjQ2CvTQ 1225459207@qq.com
The key's randomart image is:
+---[RSA 2048]----+
| oo+.o |
| ..Eo= |
| . .o+.= |
|.*..oo..o o |
|B*o*.+..S |
|O+O = . |
|*=+o |
|.Bo |
|ooo. |
+----[SHA256]-----+
- 进入 /root/.ssh/ 目录,获取密钥
root@ubuntu:/usr/local# cd /root/.ssh/
root@ubuntu:~/.ssh# vi id_rsa.pub
- 配置到 GitLab SSH 密钥中
- 克隆到容器中
root@ubuntu:/usr/local/docker# clear
root@ubuntu:/usr/local/docker# git clone ssh://git@192.168.106.133:2222/Yuu/myshop.git
Cloning into 'myshop'...
remote: Counting objects: 8426, done.
remote: Compressing objects: 100% (6921/6921), done.
remote: Total 8426 (delta 1261), reused 8423 (delta 1261)
Receiving objects: 100% (8426/8426), 21.80 MiB | 16.09 MiB/s, done.
Resolving deltas: 100% (1261/1261), done.
Checking connectivity... done.
Maven 打包
root@ubuntu:/usr/local/docker/myshop# mvn clean package -Dmaven.test.skip=true
打包镜像
-
将项目的 tar.gz 包,移入 /docker/myshop/image 目录中
-
创建 Dockerfile 文件
FROM tomcat
WORKDIR /usr/local/tomcat/webapps/ROOT
RUN rm -fr *
ADD myshop.tar.gz /usr/local/tomcat/webapps/ROOT
RUN rm -fr myshop.tar.gz
WORKDIR /usr/local/tomcat
- 构建镜像
docker build -t 192.168.106.128:5000/myshop .
- 推送镜像到私服
docker push 192.168.106.128:5000/myshop
创建一个 MyShop 容器
- 编写 docker-compose.yml 文件
version: '3.1'
services:
myshop:
restart: always
image: 192.168.106.128:5000/myshop
container_name: myshop
ports:
- 8080:8080
- 配置私服客户端
root@ubuntu:/usr/local/docker# cd /etc/docker/
root@ubuntu:/etc/docker# vi daemon.json
{
"registry-mirrors": [
"https://registry.docker-cn.com"
],
"insecure-registries": [
"ip:5000"
]
}
- 重启 Docker
$ systemctl restart docker
- 启动 myshop 容器
$ docker-compose up -d