Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4b540b7

Browse files
authored
docs: simplify Docker quickstart (#4257)
1 parent e49ef68 commit 4b540b7

File tree

8 files changed

+49
-124
lines changed

8 files changed

+49
-124
lines changed

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ site/**/*.typegen.ts
3131
site/build-storybook.log
3232

3333
# Build
34-
build/
35-
dist/
34+
/build/
35+
/dist/
3636
site/out/
3737

3838
*.tfstate
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
DROP INDEX users_email_lower_idx;

docs/admin/audit-logs.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
# Audit Logs
22

3-
This is an enterprise feature that allows **Admins** and **Auditors** to monitor what is happening in their deployment.
3+
Audit Logs allows **Admins** and **Auditors** to monitor user operations in
4+
their deployment.
45

56
## Tracked Events
67

7-
This feature tracks **create, update and delete** events for the following resources:
8+
We track **create, update and delete** events for the following resources:
89

910
- GitSSHKey
1011
- Template
@@ -31,4 +32,4 @@ The supported filters are:
3132

3233
## Enabling this feature
3334

34-
This feature is autoenabled for all enterprise deployments. An Admin can contact us to purchase a license [here](https://coder.com/contact?note=I%20want%20to%20upgrade%20my%20license).
35+
This feature is autoenabled for all enterprise deployments. Admins may contact us to purchase a license [here](https://coder.com/contact?note=I%20want%20to%20upgrade%20my%20license).

docs/images/quickstart/docker/create-workspace.png

100755100644
-177 KB
Loading

docs/quickstart/docker.md

Lines changed: 18 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -15,54 +15,29 @@ Coder with Docker has the following advantages:
1515

1616
1. [Install and launch Coder](../install)
1717

18-
You will specify `CODER_ACCESS_URL=http://localhost:7080` since we're using
19-
local Docker workspaces exclusively. `CODER_ACCESS_URL` is the external URL
20-
to access Coder. The rest of the Docker quickstart guide will assume that
21-
this is your Access URL.
22-
23-
You will also specify `CODER_ADDRESS=0.0.0.0:7080` which is the address to
24-
serve the API and dashboard.
18+
Next, we export the `CODER_ADDRESS` and `CODER_ACCESS_URL` environment
19+
variables. We can use localhost for the Access URL since the workspaces
20+
all run on the same machine. `CODER_ADDRESS` is where coder server binds
21+
while `CODER_ACCESS_URL` is where it's accessed. We use `:7080` to bind
22+
to all interfaces.
2523

2624
```bash
27-
coder server --address $CODER_ADDRESS --access-url $CODER_ACCESS_URL
25+
$ export CODER_ADDRESS=:7080
26+
$ export CODER_ACCESS_URL=http://localhost:7080
27+
$ coder server --address $CODER_ADDRESS --access-url $CODER_ACCESS_URL
2828
```
2929

3030
1. Run `coder login http://localhost:7080` in a new terminal and follow the
3131
interactive instructions to create your user.
3232

33-
1. Pull the example template:
33+
1. Pull the "Docker" example template using the interactive `coder templates init`:
3434

3535
```bash
36-
echo "docker" | coder templates init
37-
cd docker
38-
# You should see a `main.tf` file in this directory
39-
```
40-
41-
1. Open up `main.tf` in your preferred editor to edit the images
42-
43-
You can skip this step if you're fine with our default, generic OS images.
44-
45-
Search for the following section in `main.tf`:
46-
47-
```hcl
48-
...
49-
variable "docker_image" {
50-
description = "Which Docker image would you like to use for your workspace?"
51-
# The codercom/enterprise-* images are only built for amd64
52-
default = "codercom/enterprise-base:ubuntu"
53-
validation {
54-
condition = contains(["codercom/enterprise-base:ubuntu", "codercom/enterprise-node:ubuntu",
55-
"codercom/enterprise-intellij:ubuntu", "codercom/enterprise-golang:ubuntu"], var.docker_image)
56-
error_message = "Invalid Docker image!"
57-
}
58-
}
59-
...
36+
$ coder templates init
37+
$ cd docker
6038
```
6139

62-
And edit the strings in `condition = contains([...])` and `default = ...`
63-
with your preferred images.
64-
65-
1. Push up the template to Coder with `coder templates create`
40+
1. Push up the template with `coder templates create`
6641
1. Open the dashboard in your browser (http://localhost:7080) to create your
6742
first workspace:
6843

@@ -72,16 +47,20 @@ Coder with Docker has the following advantages:
7247

7348
<img src="../images/quickstart/docker/create-workspace.png">
7449

75-
Now wait a few moments for the workspace to build... After the first build
50+
Now wait a few moments for the workspace to build... After the first build,
7651
the image is cached and subsequent builds will take a few seconds.
7752

78-
1. All done!
53+
1. Your workspace is ready to go!
7954

8055
<img src="../images/quickstart/docker/ides.png">
8156

8257
Open up a web application or [SSH in](../ides.md#ssh-configuration).
8358

59+
1. If you want to modify the Docker image or template, edit the files in the
60+
previously created `./docker` directory, then run `coder templates push`.
61+
8462
## Next Steps
8563

64+
- [Port-forward](../networking/port-forwarding.md.md)
8665
- [Learn more about template configuration](../templates.md)
8766
- [Configure more IDEs](../ides/web-ides.md)

examples/templates/docker/README.md

Lines changed: 2 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,70 +9,16 @@ tags: [local, docker]
99
To get started, run `coder templates init`. When prompted, select this template.
1010
Follow the on-screen instructions to proceed.
1111

12-
## Adding/removing images
12+
## Editing the image
1313

14-
After building and pushing an image to an image registry (e.g., DockerHub), edit
15-
the template to make the image available to users:
16-
17-
```sh
18-
# Open the template
19-
vim main.tf
20-
```
21-
22-
Modify your file to match the following:
23-
24-
```diff
25-
variable "docker_image" {
26-
description = "What Docker image would you like to use for your workspace?"
27-
default = "codercom/enterprise-base:ubuntu"
28-
validation {
29-
condition = contains(["codercom/enterprise-base:ubuntu", "codercom/enterprise-node:ubuntu",
30-
- "codercom/enterprise-intellij:ubuntu"], var.docker_image)
31-
+ "codercom/enterprise-intellij:ubuntu", "codercom/enterprise-golang:ubuntu"], var.docker_image)
32-
error_message = "Invalid Docker image!"
33-
}
34-
}
35-
```
36-
37-
Update the template:
38-
39-
```sh
40-
coder template push docker
41-
```
42-
43-
You can also remove images from the validation list. Workspaces using older template versions will continue using
44-
the removed image until you update the workspace to the latest version.
14+
Edit the `Dockerfile` and run `coder templates push` to update workspaces.
4515

4616
## code-server
4717

4818
`code-server` is installed via the `startup_script` argument in the `coder_agent`
4919
resource block. The `coder_app` resource is defined to access `code-server` through
5020
the dashboard UI over `localhost:13337`.
5121

52-
## Updating images
53-
54-
To reduce drift, we recommend versioning images in your registry by creating tags. To update the image tag in the template:
55-
56-
```sh
57-
variable "docker_image" {
58-
description = "What Docker image would you like to use for your workspace?"
59-
default = "codercom/enterprise-base:ubuntu"
60-
validation {
61-
- condition = contains(["my-org/base-development:v1.1", "myorg-java-development:v1.1"], var.docker_image)
62-
+ condition = contains(["my-org/base-development:v1.1", "myorg-java-development:v1.2"], var.docker_image)
63-
64-
error_message = "Invalid Docker image!"
65-
}
66-
}
67-
```
68-
69-
Optional: Update workspaces to the latest template version:
70-
71-
```sh
72-
coder ls
73-
coder update [workspace name]
74-
```
75-
7622
## Extending this template
7723

7824
See the [kreuzwerker/docker](https://registry.terraform.io/providers/kreuzwerker/docker) Terraform provider documentation to
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
FROM ubuntu
2+
3+
RUN apt-get update && apt-get install -y curl wget git vim golang

examples/templates/docker/main.tf

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ terraform {
66
}
77
docker = {
88
source = "kreuzwerker/docker"
9-
version = "~> 2.20.2"
9+
version = "~> 2.22"
1010
}
1111
}
1212
}
@@ -55,32 +55,37 @@ resource "coder_app" "code-server" {
5555
}
5656

5757

58-
variable "docker_image" {
59-
description = "Which Docker image would you like to use for your workspace?"
60-
# The codercom/enterprise-* images are only built for amd64
61-
default = "codercom/enterprise-base:ubuntu"
62-
validation {
63-
condition = contains(["codercom/enterprise-base:ubuntu", "codercom/enterprise-node:ubuntu",
64-
"codercom/enterprise-intellij:ubuntu", "codercom/enterprise-golang:ubuntu"], var.docker_image)
65-
error_message = "Invalid Docker image!"
66-
}
67-
}
68-
6958
resource "docker_volume" "home_volume" {
7059
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}-home"
7160
}
7261

62+
63+
resource "docker_image" "main" {
64+
name = "coder-${data.coder_workspace.me.id}"
65+
build {
66+
path = "./build"
67+
}
68+
triggers = {
69+
dir_sha1 = sha1(join("", [for f in fileset(path.module, "build/*") : filesha1(f)]))
70+
}
71+
}
72+
7373
resource "docker_container" "workspace" {
7474
count = data.coder_workspace.me.start_count
75-
image = var.docker_image
75+
image = docker_image.main.name
7676
# Uses lower() to avoid Docker restriction on container names.
7777
name = "coder-${data.coder_workspace.me.owner}-${lower(data.coder_workspace.me.name)}"
7878
# Hostname makes the shell more user friendly: coder@my-workspace:~$
7979
hostname = lower(data.coder_workspace.me.name)
8080
dns = ["1.1.1.1"]
8181
# Use the docker gateway if the access URL is 127.0.0.1
8282
command = [
83-
"sh", "-c", replace(coder_agent.main.init_script, "localhost", "host.docker.internal")]
83+
"sh", "-c",
84+
<<EOT
85+
trap '[ $? -ne 0 ] && echo === Agent script exited with non-zero code. Sleeping infinitely to preserve logs... && sleep infinity' EXIT
86+
${replace(coder_agent.main.init_script, "localhost", "host.docker.internal")}
87+
EOT
88+
]
8489
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]
8590
host {
8691
host = "host.docker.internal"
@@ -92,13 +97,3 @@ resource "docker_container" "workspace" {
9297
read_only = false
9398
}
9499
}
95-
96-
resource "coder_metadata" "container_info" {
97-
count = data.coder_workspace.me.start_count
98-
resource_id = docker_container.workspace[0].id
99-
100-
item {
101-
key = "image"
102-
value = var.docker_image
103-
}
104-
}

0 commit comments

Comments
 (0)