Docker Dind Volume Issue

Hey team I’m struggling to build the following setup I have my Linux virtual machine running on Azure acting as a coder host And I have the default docker template that you provide I’m creating an workspace and installing docker inside of it Inside the workspace I’m cloning my git repo that includes an docker-compose that setups my project using VOLUMES But when I run the docker compose and I exec inside the containers, the files are actually directories, I spent some hours googling it and it seems that this is related to the docker inside my workspace actually using my host docker sock ( kind weird but I think that’s it ) and because of that docker is not able to really find the git clonned repo to be used as a volume Do you know how fix this? Or if can I use a different approach? I really need to use the docker-compose with volumes because because I need to use the hot reload feature to improve my experience
24 Replies
Codercord
Codercord2y ago
<#1120502779639762956>
Category
Help needed
Product
Coder OSS (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
kyle
kyle2y ago
I'd recommend using sysbox with Coder to allow your Docker containers to run Docker. https://coder.com/docs/v2/latest/templates/docker-in-workspaces#use-sysbox-in-docker-based-templates
Docker in Workspaces - Coder v2 Docs
Use docker inside containerized templates
nelsonsilva
nelsonsilva7mo ago
Hey @Marco Aleixo, did you managed to find a solution for your problem? I facing the same issues.
Atif
Atif7mo ago
@nelsonsilva Have you explored using the sysbox-runc? more details in the link Kyle shared above Try and update and I will be happy to help
nelsonsilva
nelsonsilva7mo ago
I was not able to put sysbox-runc working, I got it working only with a privileged sidecar container (https://coder.com/docs/v2/latest/templates/docker-in-workspaces#privileged-sidecar-container) which I understand is not optimal.
Docker in workspaces - Coder v2 Docs
Use Docker inside containerized templates
Atif
Atif7mo ago
It should be two steps. 1. Install sysbox-runc 2. Update template to to use sysbox-runc as the docker runtime It should not require a privileged container
nelsonsilva
nelsonsilva7mo ago
Where should I install sysbox-runc? On the host or on the docker container which I am running coder?
nelsonsilva
nelsonsilva7mo ago
I use docker-compose to set up coder, like the docs specifies (https://coder.com/docs/v2/latest/install/docker#requirements)
Docker - Coder v2 Docs
Install Coder with Docker / docker-compose
nelsonsilva
nelsonsilva7mo ago
In a selfhosted server
Atif
Atif7mo ago
sysbox-runc should be installed on the docker host(s) where your workspaces will be provisioned.
nelsonsilva
nelsonsilva7mo ago
Sorry but I am still not sure where to install it. Now, I set coder up using the docker-compose file and I am mounting the docker socket to the container. I am not allowed to install sysbox-runc on the host machine because we have another projects that need another runtime engine. So, do I have to install it on the docker container where I have coder or on my host machine?
Atif
Atif7mo ago
It should be on host machine in this case as you are mounting the host docker socker within the coder container So Coder will provision all workspaces on the Host
nelsonsilva
nelsonsilva7mo ago
Can I not mount the docker socket volume and then install sysbox on the container?
Atif
Atif7mo ago
Installing sysbox-runc adds sysboc-runc as an additional option for the runtime and other projects can still use other runtimes
nelsonsilva
nelsonsilva7mo ago
Ahh ok, I see Thanks, then I try it out
Atif
Atif7mo ago
But make sure you follow the intsrcutions for installing sysbox correctly
nelsonsilva
nelsonsilva7mo ago
I need to schedule it for the right time since I have to stop every container So I can't make that during a work day
Atif
Atif7mo ago
they recommend stopping and removing all running containers before installation Yes Or better set up a different docker host for Coder workspaces and use the ssh connection in your template to conect to the remote host In that case, you do not need to use the docker socket of the host machine at all.
nelsonsilva
nelsonsilva7mo ago
How can I do that? That you be much better If I didn't need the docker socket of the host machine
Atif
Atif7mo ago
You need another host another machine and install docker there with sysbox
nelsonsilva
nelsonsilva7mo ago
Unfortunately I will not be able to do that. I will try installing sysbox on my host and see if I can work from that on
Atif
Atif7mo ago
And then you can just mount the ssh key to your coder container and modify the template to use the remote docker host over ssh
nelsonsilva
nelsonsilva7mo ago
helllo @Atif, after installing sysbox on my host server, I'm having problems get it working on my docker in docker workspace. After following the docs I did not manage to put it working. Are the docs updated? I will put here how all my setup is configured, maybe it will help you better understand my problem. Coder is running using the docker-compose file based on coder docs (https://github.com/coder/coder/blob/main/docker-compose.yaml). I updated some values, but that is basically it. I create a new template using a started docker containers template. I edited the Dockerfile to use a custom one. I edited the main.tf file and include what is on coder sysbox docs (https://coder.com/docs/v2/latest/templates/docker-in-workspaces#use-sysbox-in-docker-based-templates). What I have for now is this:
resource "docker_container" "workspace" {
count = data.coder_workspace.me.start_count
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:~$
hostname = data.coder_workspace.me.name
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]

command = ["sh", "-c", coder_agent.main.init_script]
# Use the Sysbox container runtime (required)
runtime = "sysbox-runc"


host {
host = "host.docker.internal"
ip = "host-gateway"
}
volumes {
container_path = "/home/${local.username}"
volume_name = docker_volume.home_volume.name
read_only = false
}
resource "docker_container" "workspace" {
count = data.coder_workspace.me.start_count
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:~$
hostname = data.coder_workspace.me.name
env = ["CODER_AGENT_TOKEN=${coder_agent.main.token}"]

command = ["sh", "-c", coder_agent.main.init_script]
# Use the Sysbox container runtime (required)
runtime = "sysbox-runc"


host {
host = "host.docker.internal"
ip = "host-gateway"
}
volumes {
container_path = "/home/${local.username}"
volume_name = docker_volume.home_volume.name
read_only = false
}
and
resource "coder_agent" "main" {
arch = data.coder_provisioner.me.arch
os = "linux"
startup_script = <<-EOT
set -e

# Start Docker
sudo dockerd &

# Prepare user home with default files on first start.
if [ ! -f ~/.init_done ]; then
cp -rT /etc/skel ~
touch ~/.init_done
fi

# install and start code-server
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.19.1
/tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
EOT
...
resource "coder_agent" "main" {
arch = data.coder_provisioner.me.arch
os = "linux"
startup_script = <<-EOT
set -e

# Start Docker
sudo dockerd &

# Prepare user home with default files on first start.
if [ ! -f ~/.init_done ]; then
cp -rT /etc/skel ~
touch ~/.init_done
fi

# install and start code-server
curl -fsSL https://code-server.dev/install.sh | sh -s -- --method=standalone --prefix=/tmp/code-server --version 4.19.1
/tmp/code-server/bin/code-server --auth none --port 13337 >/tmp/code-server.log 2>&1 &
EOT
...
If I start the workspace, I am not able to run a simple docker run hello-world. I'm new to terraform and sorry if anything that I say or/and aks sounds stupid. Also got a warning saying Workspace is unhealthy - Your workspace is running but 1 agent is unhealthy. I don't want to use docker with sudo command behind.
Phorcys
Phorcys6mo ago
hey @nelsonsilva, your config looks good, did you have any luck?
Want results from more Discord servers?
Add your server