user3836484
user3836484

Reputation: 205

gitlab-runner - deploy docker image to a server

I can setup a gitlab-runner with docker image as below:-

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. From Google, I observe it may use "docker push" to proceed next step, such as push to AWS ECS, or somewhere of Gitlab. Actually I wish to understand, if I can push it directly to another remote server (e.g. by scp)?

Upvotes: 2

Views: 4289

Answers (1)

n2o
n2o

Reputation: 6487

A docker image is a combination of different Layers which are being built when you use the docker build command. 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.

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". 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.

You are using GitLab. GitLab provides its own registry. You can push your images to your own Gitlab registry and pull it from your remote server. 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. You can find many examples in the docs.

Upvotes: 4

Related Questions