我正在尝试将运行Ubuntu Linux 18.04的构建服务器设置为Docker主机。
主机有三个正在运行的Docker容器-Docker注册表-Gitlab服务器-Gitlab Runner(用于构建Angular Apps)
我希望Gitlab Runner容器使用nginx和已编译的Angular代码构建docker映像并将其推送到Docker Registry。
我已经设法设置了所有三个正在运行的容器,GitlabRunner正在构建角度项目,但我面临的挑战是在Gitlab Runner容器中构建Docker映像。
Docker命令在Gitlab Runner容器中不可用以构建Docker映像。
这可能吗 ??
我尝试将docker.io安装在Gitlab Runner容器中,因此在构建之后,它可以具有可用的docker命令,但仍然不走运。它仍然说码头工人不可用。
这是我的.gitlab-ci.yml文件
stages:
- build
build:
stage: build
image: node:10.9.0
script:
- npm install -g @angular/cli
- npm install -g typescript
- npm install
- ng build --prod
- docker image build -t tag/to/image .
- docker push tag/to/image
tags:
- angular
cache:
paths:
- node_modules/
artifacts:
expire_in: 1 week
paths:
- dist/*
only:
- master
这是我的nginx.conf文件
worker_processes 1;
events {
worker_connections 1024;
}
http {
server {
listen 80;
server_name localhost;
root /usr/share/nginx/html;
index index.html index.htm;
include /etc/nginx/mime.types;
gzip on;
gzip_min_length 1000;
gzip_proxied expired no-cache no-store private auth;
gzip_types text/plain text/css application/json application/javascript application/x-javascript text/xml application/xml application/xml+rss text/javascript;
location / {
try_files $uri $uri/ /index.html;
}
}
}
这是我要用来构建的Dockerfile
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
WORKDIR /usr/share/nginx/html
COPY dist/ .
在gitlab文档中,有关于如何在Gitlab-CI管道中构建docker文件的参考。这里描述了最干净,最友好的方法,效果非常好。
在我们的例子中,我们需要在管道中进行一些额外的编译,因此我们使用了python:3.6.5 docker镜像,并在其中安装了docker。
重要提示:确保您的gitlab-runner泊坞窗执行程序的“特权”设置为true
executor = "docker"
[runners.docker]
privileged = true
首先,我们在gitlab-ci.yml的顶部定义了“ install_docker”
.install_docker: &install_docker |
apt-get update
apt-get -y install apt-transport-https ca-certificates curl software-properties-common
curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian $(lsb_release -cs) stable"
apt-get update
apt-get -y install docker-ce
然后我们在工作中需要时使用它
script:
- *install_docker
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句