<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Coder &#8211; 天地一沙鸥</title>
	<atom:link href="https://haoluobo.com/tag/coder/feed/" rel="self" type="application/rss+xml" />
	<link>https://haoluobo.com</link>
	<description>to be continue....</description>
	<lastBuildDate>Wed, 16 Apr 2025 01:10:19 +0000</lastBuildDate>
	<language>zh-Hans</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.8.2</generator>
	<item>
		<title>使用 Coder 搭建云开发环境相关问题记录</title>
		<link>https://haoluobo.com/2025/04/%e4%bd%bf%e7%94%a8-coder-%e6%90%ad%e5%bb%ba%e4%ba%91%e5%bc%80%e5%8f%91%e7%8e%af%e5%a2%83%e7%9b%b8%e5%85%b3%e9%97%ae%e9%a2%98%e8%ae%b0%e5%bd%95/</link>
		
		<dc:creator><![CDATA[vicalloy]]></dc:creator>
		<pubDate>Tue, 15 Apr 2025 13:05:00 +0000</pubDate>
				<category><![CDATA[编程]]></category>
		<category><![CDATA[code-server]]></category>
		<category><![CDATA[Coder]]></category>
		<guid isPermaLink="false">https://haoluobo.com/?p=12671</guid>

					<description><![CDATA[code-server 是开源的在浏览器中运行 VS Code。如果你想搭建一套自己的远程开发环境 code- [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p><a href="https://github.com/coder/code-server">code-server</a> 是开源的在浏览器中运行 VS Code。如果你想搭建一套自己的远程开发环境 <code>code-server</code> 是一个不错的选择。如果只是给自己用  <code>code-server</code> 没什么问题，如果想提供团队使用就得配合 <a href="https://github.com/coder/coder">Coder</a> 来做用户和环境等管理。</p>



<p>下面是 Coder 使用过程中遇到问题的一些简单记录。</p>



<h2 class="wp-block-heading">Docker 镜像拉取问题</h2>



<p>在国内拉取 Docker 镜像几乎无法成功，如果使用 Docker 部署首先要修改 Docker 源。</p>



<p>Linux 下 Docker 的配置文件位于 <code>/etc/docker/daemon.json</code> 。修改 Docker 源的方法网上有很多资料，这里不再赘述。</p>



<h2 class="wp-block-heading">为 Coder 设置代理</h2>



<p>Coder 创建 Template 时需要从网络上下载资料，这一步很容易失败。通过环境变量的方式为 Coder 设置代理 <code>HTTP_PROXY 和 HTTPS_PROXY</code> 。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: yaml; title: ; notranslate">
services:
  coder:
    # This MUST be stable for our documentation and
    # other automations.
    image: ghcr.io/coder/coder:${CODER_VERSION:-latest}
    ports:
      - &quot;7080:7080&quot;
    environment:
      CODER_PG_CONNECTION_URL: &quot;postgresql://${POSTGRES_USER:-username}:${POSTGRES_PASSWORD:-password}@database/${POSTGRES_DB:-coder}?sslmode=disable&quot;
      CODER_HTTP_ADDRESS: &quot;0.0.0.0:7080&quot;
      # You&#039;ll need to set CODER_ACCESS_URL to an IP or domain
      # that workspaces can reach. This cannot be localhost
      # or 127.0.0.1 for non-Docker templates!
      # CODER_ACCESS_URL: &quot;${CODER_ACCESS_URL}&quot;
      CODER_ACCESS_URL: &quot;https://coder.your-domain.com&quot;
      HTTP_PROXY: &quot;http://your.proxy.com:1087&quot;
      HTTPS_PROXY: &quot;http://your.proxy.com:1087&quot;
    group_add:
      - &quot;124&quot; # docker group on host `getent group docker | cut -d: -f3`
    user: &quot;1000:1000&quot;
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - ./coder_home:/home/coder
    depends_on:
      database:
        condition: service_healthy
  database:
    image: &quot;docker.1ms.run/postgres:16&quot;
    environment:
      POSTGRES_USER: ${POSTGRES_USER:-username} # The PostgreSQL user (useful to connect to the database)
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD:-password} # The PostgreSQL password (useful to connect to the database)
      POSTGRES_DB: ${POSTGRES_DB:-coder} # The PostgreSQL default database (automatically created at first launch)
    volumes:
      - ./coder_data:/var/lib/postgresql/data # Use &quot;docker volume rm coder_coder_data&quot; to reset Coder
    healthcheck:
      test:
        &#x5B;
          &quot;CMD-SHELL&quot;,
          &quot;pg_isready -U ${POSTGRES_USER:-username} -d ${POSTGRES_DB:-coder}&quot;,
        ]
      interval: 5s
      timeout: 5s
      retries: 5
</pre></div>


<h2 class="wp-block-heading">编辑 Template</h2>



<h3 class="wp-block-heading">在 Template 中设置代理</h3>



<p>通过 Template 创建 Workspace 依旧会用到网络，这一步依旧很难成功。在 <code>resource "coder_agent" "main"</code> 中添加  <code>HTTP_PROXY</code> 和 <code>HTTPS_PROXY</code>。</p>



<h3 class="wp-block-heading">Docker in Docker</h3>



<p>如果要在 Workspace 中调用 Docker，需要将 <code>docker.sock</code> 映射给 workspace，且需要将传入的路径转换为 HOST 的文件路径。还需要将 HOST 的 docker 用户组添加给 coder 用户。</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
# ...
resource &quot;coder_agent&quot; &quot;main&quot; {
  # ...
  env = {
    # ...
    HTTP_PROXY          = &quot;http://your-proxy.com:1087&quot;
    HTTPS_PROXY         = &quot;http://your-proxy.com:1087&quot;
  }
  # ...
}

resource &quot;docker_container&quot; &quot;workspace&quot; {
  # ...
  group_add  = &#x5B;&quot;124&quot;]  # host 的 docker 用户组id
  # unsafe, should https://coder.com/docs/v2/latest/templates/docker-in-workspaces#use-sysbox-in-docker-based-templates
  volumes {
    host_path = &quot;/var/run/docker.sock&quot;
    container_path = &quot;/var/run/docker.sock&quot;
  }
  # ...
}
</pre></div>


<h3 class="wp-block-heading">禁用 autostop</h3>



<p>为节约服务器资源，长期不用的 workspace 会被自动销毁，下次使用时再进行重建。如果服务用的人不多，资源足够，建议把 autostop 关闭掉。</p>



<p>选中 template 并进入 template 的 settings 并在 schedule 中将 default autostop 修改为 0。</p>
]]></content:encoded>
					
		
		
			</item>
	</channel>
</rss>
