我想知道在工作站上运行 Che 时使用自定义 Eclipse Che 堆栈的便捷方法是什么。
我真的很喜欢 Eclipse Che 的概念:为不同的开发环境拥有单独的 Che 工作区(Docker 容器),并安装相应的工具。工作区从 Che 堆栈初始化。堆栈可以定义为 Docker 镜像,也可以使用 Dockerfiles 或 Docker composer 文件动态创建。
1.按配方定义堆栈(Dockerfile)
我编写了我的自定义 Dockerfile 用于测试目的:
FROM eclipse/stack-base:ubuntu
RUN sudo apt-get update
RUN sudo apt-get install -y apt-transport-https
RUN sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
RUN echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
RUN curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
RUN sudo apt-get install -y nodejs build-essential mongodb-org
RUN sudo apt-get clean
RUN sudo apt-get -y autoremove
RUN sudo apt-get -y clean
RUN sudo rm -rf /var/lib/apt/lists/*
Run Code Online (Sandbox Code Playgroud)
它基于文档中eclipse/stack-base:ubuntu建议的图像
然后我使用Build Stack From Recipe创建了 Che 堆栈。
之后,我基于此堆栈创建了一个工作区,它运行正常。
这种方法有一个明显的缺点:在我的工作站重新启动后,Che 会从 Dockerfile 重建工作区!只要 Dockerfile 包含安装命令,该过程就会花费大量时间,并且显然需要互联网连接。
2. 基于本地Docker镜像的栈
我使用我的自定义 Dockerfile 在本地构建 docker 镜像:
sudo docker build -f custom.dockerfile -t my-custom-image .
然后我使用以下配置创建了两个 Che 堆栈:
{
  "scope": "general",
  "description": "Custom1",
  "tags": [],
  "workspaceConfig": {
    "environments": {
      "default": {
        "recipe": {
          "contentType": "text/x-dockerfile",
          "type": "dockerfile",
          "content": "FROM my-custom-image\n"
        },
        "machines": {
          "dev-machine": {
            "servers": {},
            "agents": [
              "org.eclipse.che.ws-agent",
              "org.eclipse.che.ssh",
              "org.eclipse.che.terminal",
              "org.eclipse.che.exec"
            ],
            "attributes": {
              "memoryLimitBytes": "2147483648"
            }
          }
        }
      }
    },
    "defaultEnv": "default",
    "commands": [],
    "projects": [],
    "name": "default",
    "links": []
  },
  "components": [],
  "creator": "che",
  "name": "my-custom-1",
  "id": "stackx6hs410a9awhu299"
}
{
  "scope": "general",
  "description": "Custom2",
  "tags": [],
  "workspaceConfig": {
    "environments": {
      "default": {
        "recipe": {
          "contentType": "application/x-yaml",
          "type": "compose",
          "content": "services:\n dev-machine:\n  image: my-custom-image\n"
        },
        "machines": {
          "dev-machine": {
            "servers": {},
            "agents": [
              "org.eclipse.che.exec",
              "org.eclipse.che.terminal",
              "org.eclipse.che.ws-agent",
              "org.eclipse.che.ssh"
            ],
            "attributes": {
              "memoryLimitBytes": "2147483648"
            }
          }
        }
      }
    },
    "defaultEnv": "default",
    "commands": [],
    "projects": [],
    "name": "custom",
    "links": []
  },
  "components": [],
  "creator": "che",
  "name": "my-custom-2",
  "id": "stack55s3tso56cljsf30"
}
Run Code Online (Sandbox Code Playgroud)基于这些堆栈的工作区无法创建并出现错误:
Could not start workspace my-custom-1. Reason: Start of environment 'default' failed. Error: Docker image build failed. Image id not found in build output.
Could not start workspace my-custom-2. Reason: Start of environment 'default' failed. Error: Can't create machine from image. Cause: Error response from docker API, status: 404, message: repository my-node-mongo not found: does not exist or no pull access
看起来 Che 在我的工作站上看不到 Docker 图像。
所以问题是:有没有什么办法可以让车实现我的目标?还是 Che 不适合我?
3. 设置本地 docker 注册表 ( https://docs.docker.com/registry/ )
设置本地 docker 注册表:https : //docs.docker.com/registry/deploying/
使用 Dockerfile 构建自定义镜像
sudo docker build -f custom.dockerfile -t my-custom-image .
标记它并将其推送到本地注册表
sudo docker tag my-custom-image localhost:5000/my-custom-image
sudo docker push localhost:5000/my-custom-image
Run Code Online (Sandbox Code Playgroud)使用图像创建自定义堆栈 localhost:5000/my-custom-image
这种方法有效,但有一个明显的缺点:必须维护 docker registry。
无论如何它都有效,我可以在我的愿望清单中勾选两个复选框。