Create a worskpace with several container

Hi, I'd like to know whether it's possible in coder to create a workspace that contains for example a container where all code resides and gets executed (as usual) and additionally other containers (for example a database container) that can be accessible from the former application container. Thanks !
Solution:
```tf data "coder_workspace" "me" {} resource "docker_network" "me" { name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}" }...
Jump to solution
7 Replies
Codercord
Codercord8mo ago
<#1232347535817834597>
Category
Help needed
Product
Coder OSS (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
Atif
Atif8mo ago
You have two options. 1. You set up a template with multiple docker_container resources 2. Use Docker in Workspace: https://coder.com/docs/v2/latest/templates/docker-in-workspaces
Docker in workspaces - Coder v2 Docs
Use Docker inside containerized templates
correctamundo
correctamundoOP8mo ago
Thanks a lot @Atif for your answer , I'm going to try the option 1 you suggest, will the containers have a dedicated network or is this something I have to specify on the template as well?
Atif
Atif8mo ago
I have not tried it but you can probably create a network per workspace using docker_network resource and then attach your docker_container resources to that network using https://registry.terraform.io/providers/kreuzwerker/docker/latest/docs/resources/container#nestedblock--networks_advanced
correctamundo
correctamundoOP8mo ago
Great stuff, thanks again Atif !
Solution
Atif
Atif8mo ago
data "coder_workspace" "me" {}
resource "docker_network" "me" {
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}"
}
resource "docker_container" "dev" {
...
networks_advanced {
name = docker_network.me.name
}
}
resource "docker_container" "database" {
...
networks_advanced {
name = docker_network.me.name
}
}
data "coder_workspace" "me" {}
resource "docker_network" "me" {
name = "coder-${data.coder_workspace.me.owner}-${data.coder_workspace.me.name}"
}
resource "docker_container" "dev" {
...
networks_advanced {
name = docker_network.me.name
}
}
resource "docker_container" "database" {
...
networks_advanced {
name = docker_network.me.name
}
}
Atif
Atif8mo ago
Something like that could work.
Want results from more Discord servers?
Add your server