0

I will run docker on a dedicated sever by a service provider. It is not possible to install docker on this server. Apache, Git and a lot more is installed. So I try to run docker in a container. I will pull a docker image from the gitlab registry and run in a sub domain. I wrote a .gitlab-ci.yml. But I get an error message.

I found this answer:

You can't (*) run Docker inside Docker containers or images. You can't (*) start background services inside a Dockerfile. As you say, commands like systemctl and service don't (*) work inside Docker anywhere. And in any case you can't use any host-system resources, including the host's Docker socket, from anywhere in a Dockerfile.

How do I solve this problem?

$ sudo docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
ERROR: Job failed: exit code 1

.gitlab-ci.yml

image: ubuntu:latest

before_script:
  - apt-get update
  - apt-get install -y apt-transport-https ca-certificates curl software-properties-common

  - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add
  - apt-key fingerprint 0EBFCD88
  - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

stages:
    - test

test:
  stage: test
  script:
    - apt-get update
    - apt-cache search docker-ce
    - apt-get install -y docker-ce
    - docker run -d hello-world
David Maze
  • 130,717
  • 29
  • 175
  • 215
Aaron
  • 769
  • 1
  • 14
  • 25
  • Hi, it works with sudo? – Kilian Nov 14 '18 at 10:14
  • I tried with sudo, but without success. – Aaron Nov 14 '18 at 10:26
  • Possible duplicate of [How to run docker container inside docker (DIND)?](https://stackoverflow.com/questions/45928958/how-to-run-docker-container-inside-docker-dind) – Shardj Nov 14 '18 at 11:58
  • The usual answer is to give your container access to the host’s Docker socket `-v /var/run/docker.sock:/var/run/docker.sock`; given that and appropriate Unix permissions you can launch other containers (and also do whatever you want on the host). – David Maze Nov 14 '18 at 14:35
  • Hi, could you try attaching DinD as a service? – M. Falzone Nov 15 '18 at 07:52

2 Answers2

0

This .gitlab-ci.yml works for me.

image: ubuntu:latest

services:
  - docker:dind

variables:
  DOCKER_DRIVER: overlay2
  DOCKER_HOST: tcp://docker:2375/

before_script:
  - apt-get update
  - apt-get install -y apt-transport-https ca-certificates curl software-properties-common
  - curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add
  - apt-key fingerprint 0EBFCD88
  - add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
  - apt-get update

stages:
    - test

test:
  stage: test
  script:
    - apt-get install -y docker-ce
    - docker info
    - docker pull ...
    - docker run -p 8000:8000 -d --name ...
Aaron
  • 769
  • 1
  • 14
  • 25
0

The answer that you found.... is a little old. There are options to run systemd in a container and it is also possible to run some systemctl-replacement script.

However, I am not sure what application you really want to install.

Guido U. Draheim
  • 3,038
  • 1
  • 20
  • 19