coder icon indicating copy to clipboard operation
coder copied to clipboard

Use docker in workspace

Open capjiang opened this issue 1 year ago • 4 comments

I used curl -L https://coder.com/install.sh | sh to deploy Coder and installed Sysbox and Docker, but still unable to use Docker in the workspace normally. I have added Coder to the Docker user group. These are the two different templates I tried.

  1. starter template Docker Containers ( I downloaded Docker in the workspace.)
  2. starter template Docker Containers but image = "codercom/ubuntu-docker:latest" error docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.

capjiang avatar Apr 24 '24 03:04 capjiang

Are you certain the Coder user is in the Docker group?

You can try sudo su coder and running docker ps to see if the perms are correct.

kylecarbs avatar Apr 24 '24 10:04 kylecarbs

Are you certain the Coder user is in the Docker group?

You can try sudo su coder and running docker ps to see if the perms are correct.

Snipaste_2024-04-25_09-52-12 It's indeed in the Docker group.

capjiang avatar Apr 25 '24 01:04 capjiang

There is a way to get workspace to use Docker which is on a host Dockerfile

RUN apt-get update \
	&& apt-get install -y \
	curl \
	git \
	golang \
	sudo \
	vim \
	wget \
	# add docker cli
	docker.io \
	&& rm -rf /var/lib/apt/lists/*

main.tf

resource "docker_container" "workspace" {
  # add
  volumes {
    host_path = "/var/run/docker.sock"
    container_path = "/var/run/docker.sock"
  }
}

image Is there a good way to use Docker in this workspace and still keep Ubuntu.

capjiang avatar Apr 25 '24 08:04 capjiang

This gives the workspace full access to the host docker socket, which is unsafe. You should check this guide for a safer way to do this.

matifali avatar Apr 25 '24 20:04 matifali