简体   繁体   English

gitlab-runner - 将 docker 镜像部署到服务器

[英]gitlab-runner - deploy docker image to a server

I can setup a gitlab-runner with docker image as below:-我可以使用 docker 图像设置一个 gitlab-runner,如下所示:-

stages:
  - build
  - test
  - deploy

image: laravel/laravel:v1

build:
  stage: build
  script: 
    - npm install
    - composer install
    - cp .env.example .env
    - php artisan key:generate
    - php artisan storage:link

test:
  stage: test
  script: echo "Running tests"    

deploy_staging:
  stage: deploy
  script:
    - echo "What shall I do?"
  environment:
    name: staging
    url: https://staging.example.com
  only:
  - master

It can pass the build stage and test stage, and I believe a docker image/container is ready for deployment.它可以通过构建阶段和测试阶段,我相信一个 docker 镜像/容器已准备好部署。 From Google, I observe it may use "docker push" to proceed next step, such as push to AWS ECS, or somewhere of Gitlab.从 Google 那里,我观察到它可能会使用“docker push”来进行下一步,例如推送到 AWS ECS 或 Gitlab 的某个地方。 Actually I wish to understand, if I can push it directly to another remote server (eg by scp)?其实我想明白,如果我可以将它直接推送到另一个远程服务器(例如通过 scp)?

A docker image is a combination of different Layers which are being built when you use the docker build command. docker 镜像是使用docker build命令docker build的不同层的组合。 It reuses existing Layers and gives the combination of layers a name, which is your image name.它重用现有的图层并为图层组合命名,这就是您的图像名称。 They are usually stored somewhere in /var/lib/docker .它们通常存储在/var/lib/docker某个地方。

In general all necessary data is stored on your system, yes.一般来说,所有必要的数据都存储在您的系统上,是的。 But it is not advised to directly copy these layers to a different machine and I am not quite sure if this would work properly.但是不建议直接将这些层复制到不同的机器上,我不太确定这是否能正常工作。 Docker advises you to use a " docker registry ". Docker 建议您使用“ docker registry ”。 Installing an own registry on your remote server is very simple, because the registry can also be run as a container (see the docs ).在远程服务器上安装自己的注册表非常简单,因为注册表也可以作为容器运行(请参阅文档)。

I'd advise you to stick to the proposed solution's from the docker team and use the public DockerHub registry or an own registry if you have sensitive data.如果您有敏感数据,我建议您坚持使用 docker 团队提出的解决方案,并使用公共 DockerHub 注册表或自己的注册表。

You are using GitLab.您正在使用 GitLab。 GitLab provides its own registry . GitLab 提供了自己的注册表 You can push your images to your own Gitlab registry and pull it from your remote server.您可以将您的图像推送到您自己的 Gitlab 注册表并从您的远程服务器中提取它。 Your remote server only needs to authenticate against your registry and you're done.您的远程服务器只需要根据您的注册表进行身份验证即可。 GitLab's CI can directly build and push your images to your own registry on each push to the master-branch, for example.例如,GitLab 的 CI 可以在每次推送到主分支时直接构建和推送你的镜像到你自己的注册表。 You can find many examples in the docs .您可以在文档中找到许多示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM