我将由服务提供商在专用服务器上运行docker。它不是 可以在此服务器上安装docker。 Apache,Git等等 已安装。所以我尝试在容器中运行docker。我将拉一个码头工人形象 从gitlab注册表中运行,并在子域中运行。我写了一个.gitlab-ci.yml。但 我收到一条错误消息。
我发现了this answer:
您不能(*)在Docker容器或映像中运行Docker。你不能(*) 在Dockerfile中启动后台服务。就像你说的那样 systemctl和服务无法(*)在Docker内部的任何地方工作。而且无论如何 您不能使用任何主机系统资源,包括主机的Docker套接字, 从Dockerfile中的任何地方。
我该如何解决这个问题?
$ 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
答案 0 :(得分:0)
这个.gitlab-ci.yml为我工作。
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 ...
答案 1 :(得分:0)
您找到的答案...有点旧了。有一些选项可以在容器中运行systemd,也可以运行一些systemctl-replacement脚本。
但是,我不确定您真正要安装什么应用程序。