[英]Building Docker Image within Gitlab Runner Container
I am trying to setup a build server that is running Ubuntu Linux 18.04 as a docker host. 我正在尝试设置一个运行Ubuntu Linux 18.04作为docker主机的构建服务器。
host has three docker containers running - Docker Registry - Gitlab Server - Gitlab Runner (to build Angular Apps) 主机有三个docker容器运行 - Docker Registry - Gitlab Server - Gitlab Runner(用于构建Angular Apps)
I want Gitlab Runner container to build docker image with nginx and compiled Angular code and push it to Docker Registry. 我希望Gitlab Runner容器用nginx构建docker镜像并编译Angular代码并将其推送到Docker Registry。
I have manage to setup all three containers running and Gitlab runner is building angular project but challenge I am facing is building docker image in Gitlab Runner container. 我已经设法运行所有三个容器运行,Gitlab运行器正在构建角度项目,但我面临的挑战是在Gitlab Runner容器中构建docker镜像。
Docker command is not available within Gitlab Runner container to build docker image. 在Gitlab Runner容器中无法使用Docker命令来构建docker镜像。
Is this possible ?? 这可能吗 ??
I have tried to install docker.io within Gitlab Runner container so after time of build, it can have docker command available but still not luck. 我曾尝试在Gitlab Runner容器中安装docker.io,所以在构建之后,它可以使用docker命令,但仍然没有运气。 It still says docker not available.
它仍然说码头不可用。
Here is my .gitlab-ci.yml file 这是我的.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
here is my nginx.conf file 这是我的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;
}
}
}
here is the Dockerfile I want to use to make a build 这是我想用来构建的Dockerfile
FROM nginx:alpine
COPY nginx.conf /etc/nginx/nginx.conf
WORKDIR /usr/share/nginx/html
COPY dist/ .
In the gitlab documentation there is a reference to how to build docker files in the Gitlab-CI pipelines. 在gitlab文档中,有一个关于如何在Gitlab-CI管道中构建docker文件的参考。 The cleanest and nicest way is described here which works extremly well.
这里描述了最干净,最好的方式,效果非常好。
In our case, we needed some extra compiling in our pipeline so we used python:3.6.5 docker image and just installed the docker in it. 在我们的例子中,我们需要在管道中进行一些额外的编译,因此我们使用了python:3.6.5 docker image并在其中安装了docker。
Important: Make sure your gitlab-runner docker executor has 'privileged' set to true 重要提示:确保您的gitlab-runner docker executor将'privileged'设置为true
executor = "docker"
[runners.docker]
privileged = true
First we defined the "install_docker" at the top of the gitlab-ci.yml 首先,我们在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
Then we use it when needed inside the job 然后我们在工作中需要时使用它
script:
- *install_docker
在我的项目中,我通常在Dockerfile中执行构建步骤,并在我的.gitlab-ci.yml上使用docker :image ,因此安装的Docker是我在运行器上需要的唯一依赖项。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.