Skip to content

Commit 9faa39a

Browse files
authored
example: added docker local workspace (#1025)
1 parent 48a6cd9 commit 9faa39a

File tree

2 files changed

+56
-0
lines changed

2 files changed

+56
-0
lines changed

examples/docker-local/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: Develop in Docker on the same host that runs Coder
3+
description: Get started with Linux development using a Docker container locally as workspace provider.
4+
tags: [local, docker]
5+
---

examples/docker-local/main.tf

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
terraform {
2+
required_providers {
3+
coder = {
4+
source = "coder/coder"
5+
version = "~> 0.3.1"
6+
}
7+
docker = {
8+
source = "kreuzwerker/docker"
9+
version = "~> 2.16.0"
10+
}
11+
}
12+
}
13+
14+
provider "docker" {
15+
host = "unix:///var/run/docker.sock"
16+
}
17+
18+
data "coder_workspace" "me" {
19+
}
20+
21+
resource "coder_agent" "dev" {
22+
arch = "amd64"
23+
os = "linux"
24+
}
25+
26+
variable "docker_image" {
27+
description = "What docker image would you like to use for your workspace?"
28+
default = "codercom/enterprise-base:ubuntu"
29+
validation {
30+
condition = contains(["codercom/enterprise-base:ubuntu", "codercom/enterprise-node:ubuntu", "codercom/enterprise-java:ubuntu"], var.docker_image)
31+
error_message = "Invalid Docker Image!"
32+
}
33+
}
34+
35+
resource "docker_volume" "coder_volume" {
36+
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
37+
}
38+
39+
resource "docker_container" "workspace" {
40+
count = data.coder_workspace.me.start_count
41+
image = var.docker_image
42+
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}-root"
43+
dns = ["1.1.1.1"]
44+
command = ["sh", "-c", coder_agent.dev.init_script]
45+
env = ["CODER_TOKEN=${coder_agent.dev.token}"]
46+
volumes {
47+
container_path = "/home/coder/"
48+
volume_name = docker_volume.coder_volume.name
49+
read_only = false
50+
}
51+
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy