首页 > 解决方案 > 在专用服务器上的 docker 中运行 docker?

问题描述

我将在服务提供商的专用服务器上运行 docker。无法在此服务器上安装 docker。安装了 Apache、Git 等等。所以我尝试在容器中运行 docker。我将从 gitlab 注册表中提取一个 docker 映像并在子域中运行。我写了一个.gitlab-ci.yml。但我收到一条错误消息。

我找到了这个答案

您不能 (*) 在 Docker 容器或映像中运行 Docker。您不能 (*) 在 Dockerfile 中启动后台服务。正如你所说,像 systemctl 和 service 这样的命令在 Docker 中的任何地方都不能(*)工作。在任何情况下,您都不能从 Dockerfile 中的任何位置使用任何主机系统资源,包括主机的 Docker 套接字。

我该如何解决这个问题?

$ 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

标签: dockerdocker-composedockerfilegitlab-cigitlab-ci-runner

解决方案


你找到的答案......有点老了。有一些选项可以在容器中运行 systemd,也可以运行一些systemctl-replacement脚本。

但是,我不确定您真正想要安装什么应用程序。


推荐阅读