docs: simplify Docker quickstart (#4257)

This commit is contained in:
Ammar Bandukwala
2022-09-29 17:55:15 -05:00
committed by GitHub
parent e49ef68ebc
commit 4b540b7c42
8 changed files with 49 additions and 124 deletions
+2 -56
View File
@@ -9,39 +9,9 @@ tags: [local, docker]
To get started, run `coder templates init`. When prompted, select this template.
Follow the on-screen instructions to proceed.
## Adding/removing images
## Editing the image
After building and pushing an image to an image registry (e.g., DockerHub), edit
the template to make the image available to users:
```sh
# Open the template
vim main.tf
```
Modify your file to match the following:
```diff
variable "docker_image" {
description = "What Docker image would you like to use for your workspace?"
default = "codercom/enterprise-base:ubuntu"
validation {
condition = contains(["codercom/enterprise-base:ubuntu", "codercom/enterprise-node:ubuntu",
- "codercom/enterprise-intellij:ubuntu"], var.docker_image)
+ "codercom/enterprise-intellij:ubuntu", "codercom/enterprise-golang:ubuntu"], var.docker_image)
error_message = "Invalid Docker image!"
}
}
```
Update the template:
```sh
coder template push docker
```
You can also remove images from the validation list. Workspaces using older template versions will continue using
the removed image until you update the workspace to the latest version.
Edit the `Dockerfile` and run `coder templates push` to update workspaces.
## code-server
@@ -49,30 +19,6 @@ the removed image until you update the workspace to the latest version.
resource block. The `coder_app` resource is defined to access `code-server` through
the dashboard UI over `localhost:13337`.
## Updating images
To reduce drift, we recommend versioning images in your registry by creating tags. To update the image tag in the template:
```sh
variable "docker_image" {
description = "What Docker image would you like to use for your workspace?"
default = "codercom/enterprise-base:ubuntu"
validation {
- condition = contains(["my-org/base-development:v1.1", "myorg-java-development:v1.1"], var.docker_image)
+ condition = contains(["my-org/base-development:v1.1", "myorg-java-development:v1.2"], var.docker_image)
error_message = "Invalid Docker image!"
}
}
```
Optional: Update workspaces to the latest template version:
```sh
coder ls
coder update [workspace name]
```
## Extending this template
See the [kreuzwerker/docker](https://registry.terraform.io/providers/kreuzwerker/docker) Terraform provider documentation to
@@ -0,0 +1,3 @@
FROM ubuntu
RUN apt-get update && apt-get install -y curl wget git vim golang
+19 -24
View File
@@ -6,7 +6,7 @@ terraform {
}
docker = {
source = "kreuzwerker/docker"
version = "~> 2.20.2"
version = "~> 2.22"
}
}
}
@@ -55,24 +55,24 @@ resource "coder_app" "code-server" {
}
variable "docker_image" {
description = "Which Docker image would you like to use for your workspace?"
# The codercom/enterprise-* images are only built for amd64
default = "codercom/enterprise-base:ubuntu"
validation {
condition = contains(["codercom/enterprise-base:ubuntu", "codercom/enterprise-node:ubuntu",
"codercom/enterprise-intellij:ubuntu", "codercom/enterprise-golang:ubuntu"], var.docker_image)
error_message = "Invalid Docker image!"
}
}
resource "docker_volume" "home_volume" {
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}-home"
}
resource "docker_image" "main" {
name = "coder-${data.coder_workspace.me.id}"
build {
path = "./build"
}
triggers = {
dir_sha1 = sha1(join("", [for f in fileset(path.module, "build/*") : filesha1(f)]))
}
}
resource "docker_container" "workspace" {
count = data.coder_workspace.me.start_count
image = var.docker_image
image = docker_image.main.name
# Uses lower() to avoid Docker restriction on container names.
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
# Hostname makes the shell more user friendly: coder@my-workspace:~$
@@ -80,7 +80,12 @@ resource "docker_container" "workspace" {
dns = ["1.1.1.1"]
# Use the docker gateway if the access URL is 127.0.0.1
command = [
"sh", "-c", replace(coder_agent.main.init_script, "localhost", "host.docker.internal")]
"sh", "-c",
<<EOT
trap '[ $? -ne 0 ] && echo === Agent script exited with non-zero code. Sleeping infinitely to preserve logs... && sleep infinity' EXIT
${replace(coder_agent.main.init_script, "localhost", "host.docker.internal")}
EOT
]
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
host {
host = "host.docker.internal"
@@ -92,13 +97,3 @@ resource "docker_container" "workspace" {
read_only = false
}
}
resource "coder_metadata" "container_info" {
count = data.coder_workspace.me.start_count
resource_id = docker_container.workspace[0].id
item {
key = "image"
value = var.docker_image
}
}