How do i deploy from GitLab CI to Google Container Engine instance using Docker?

I am trying to set up automated deployment using a GitLab CI runner to deploy our 4-container app via docker-compose. I can pull the container images down using docker pull commands, but I’m stuck on how to connect to the Google Compute Engine instance in order to run the full docker-compose script.

Typically, from my local machine, I run something like:

  • Reducing the shipping time in continuous delivery, especially in hotfix
  • ADD or COPY a folder in Docker
  • Installing postgre driver in php7-fpm Docker container
  • Storing and analyzing electricity and payment data in open source DB
  • Make a CMD effect on docker run but not in docker start
  • Service docker start not work(daemon), ubuntu-15.10, To run dockerfile with intelliJ
  • eval $(docker-machine env <machine-instance>)
    docker-compose up -d
    

    But my .gitlab-ci.yml script doesn’t have docker-machine available.

    1. Do I have to install docker-machine via the script section in my
      .gitlab-ci.yml file?
    2. How do I provision the instance without
      creating a new one every time? Normally, from my local host, I would
      run docker-machine create ... once then just use the eval
      command above to reconnect to the instance. But how would this work
      with CI?

    Here’s a sample of my .gitlab-ci.yml:

    deploy staging:
        image: docker:latest
        services:
            - docker:dind
        environment: staging
        stage: deploy
        before_script:
            - docker login -u gitlab-ci-token -p $CI_BUILD_TOKEN my-registry.githost.io
        script:
            - docker pull my-registry.githost.io/group/project1:develop
            - docker pull my-registry.githost.io/group/project2:develop
            - docker pull my-registry.githost.io/group/project3:develop
            - docker pull my-registry.githost.io/group/project4:develop
            - docker-machine ls
    

  • Integrating Docker-Machine with Amazon EC2
  • docker not exposing the port with network host
  • error: unable to unlink old 'gulpfile.js' (Permission denied) while using Docker Compose for development environment
  • Docker - browsing to docker container using its IP
  • How to add Zend Guard Loader support in docker php official image instance?
  • Visual studio 2017 docker error running app
  • 2 Solutions collect form web for “How do i deploy from GitLab CI to Google Container Engine instance using Docker?”

    Not sure what you need docker-machine for in this case. You might want to get rid of it.

    But to go back to your question, the docker image you’re using does not come with neither docker-machine, nor docker-compose :

    https://github.com/docker-library/docker/blob/36e2107fb879d5d5c3dbb5d8d93aeef0a2d45ac8/1.12/Dockerfile

    So you will need to create a new image (or find an existing one) that comes with those two installed.
    So in the .gitlab-ci.yml, instead of image: docker:latest, it’s going to be something like image: mydocker

    You maybe have to install docker-machine in the GitLab CI Runner to use it with GCE

    https://docs.docker.com/machine/install-machine/

    https://docs.docker.com/machine/drivers/gce/

    Docker will be the best open platform for developers and sysadmins to build, ship, and run distributed applications.