简体   繁体   中英

Keeping docker builds in Gitlab CI with docker-compose

I have a repository that includes three parts: frontend, admin and server. Each contains its own Dockerfile.

After building the image I wanted to add a test for admin . My tests go through but take a lot of time because it pulls the base image and builds everything from scratch on each stage (like 8mins per stage). This is my .gitlab-ci.yml

image: tmaier/docker-compose

services:
  - docker:dind

stages:
  - build
  - test

build:
  stage: build
  script:
    - docker login -u $CI_DEPLOY_USER -p $CI_DEPLOY_PASSWORD $CI_REGISTRY
    - docker-compose build
    - docker-compose push

test:admin:
  stage: test
  script:
    - docker-compose -f docker-compose.yml -f docker-compose.test.yml up admin

I am not quite sure if I need to push/pull images between stages or if I should do that with artifacts/cache/whatever. As I understood I only need to push/pull if I want to deploy my images to another server. But also I added a docker-compose push which runs through but Gitlab doesn't show me any images in my registry.

I have been researching a lot on this but most example code I found was only about a single docker container and they didn't make use of docker-compose.

Any ideas? :)

Mark could you show the files docker-compose.yml docker-compose.test.yml? May be you try to push and pull different images. BTW try place docker login at before_script section that make it works at all jobs.

Gitlab currently has no way to share Docker images between stages as artifacts. They have had an outstanding feature request for this for 3 years.

You'll need to push the docker image to the docker registry and pull it in later stages that need it. (Or do everything related to the image in one stage)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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