Docker in Docker with sysbox cant find the deamon

Hello, I have installed coder with docker-compose. Also installed sysbox on the host that coder runs. I am trying to get docker to work inside the docker container but i get cannot connect to the docker daemon at unix:///var/run/docker.sock. is the docker daemon running? My dockerfile is the following:
FROM ubuntu

RUN apt-get update \
&& apt-get install -y \
curl \
ca-certificates \
git \
golang \
sudo \
vim \
wget \
# Install Python
python3 \
python3-pip \
python3-venv \
python3-dev \
&& rm -rf /var/lib/apt/lists/*

# Install nodejs and MegaLinter globally
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - \
&& sudo apt-get install -y nodejs \
&& sudo npm install mega-linter-runner -g

# Add Docker's official GPG key:
RUN sudo install -m 0755 -d /etc/apt/keyrings \
&& sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc \
&& sudo chmod a+r /etc/apt/keyrings/docker.asc \
&& echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Docker install
RUN sudo apt-get update \
&& sudo apt-get install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin

# Fix locale
RUN sudo apt-get update \
&& apt-get install -y locales \
&& sudo locale-gen en_US.UTF-8 \
&& sudo update-locale LANG=en_US.UTF-8

ARG USER=coder
RUN useradd --groups sudo --no-create-home --shell /bin/bash ${USER} \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \
&& chmod 0440 /etc/sudoers.d/${USER}
USER ${USER}
WORKDIR /home/${USER}

# Add user to docker group
RUN sudo usermod -aG docker $USER \
&& newgrp docker
FROM ubuntu

RUN apt-get update \
&& apt-get install -y \
curl \
ca-certificates \
git \
golang \
sudo \
vim \
wget \
# Install Python
python3 \
python3-pip \
python3-venv \
python3-dev \
&& rm -rf /var/lib/apt/lists/*

# Install nodejs and MegaLinter globally
RUN curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash - \
&& sudo apt-get install -y nodejs \
&& sudo npm install mega-linter-runner -g

# Add Docker's official GPG key:
RUN sudo install -m 0755 -d /etc/apt/keyrings \
&& sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc \
&& sudo chmod a+r /etc/apt/keyrings/docker.asc \
&& echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Docker install
RUN sudo apt-get update \
&& sudo apt-get install -y \
docker-ce \
docker-ce-cli \
containerd.io \
docker-buildx-plugin \
docker-compose-plugin

# Fix locale
RUN sudo apt-get update \
&& apt-get install -y locales \
&& sudo locale-gen en_US.UTF-8 \
&& sudo update-locale LANG=en_US.UTF-8

ARG USER=coder
RUN useradd --groups sudo --no-create-home --shell /bin/bash ${USER} \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \
&& chmod 0440 /etc/sudoers.d/${USER}
USER ${USER}
WORKDIR /home/${USER}

# Add user to docker group
RUN sudo usermod -aG docker $USER \
&& newgrp docker
Attached is the main.tf
20 Replies
Codercord
Codercord4mo ago
<#1288148601612275774>
Category
Help needed
Product
Coder OSS (v2)
Platform
Linux
Logs
Please post any relevant logs/error messages.
anubis
anubisOP4mo ago
Attached is the main.tf. Also when i run docker inspect --format='{{.HostConfig.Runtime}}' coder-workspace i get sysbox-runc so i guess that part is configured properly.
Phorcys
Phorcys4mo ago
@anubis what's the error?
anubis
anubisOP4mo ago
@Phorcys sorry it seems i pasted the wrong thing. the error is: cannot connect to the docker daemon at unix:///var/run/docker.sock. is the docker daemon running?
Phorcys
Phorcys4mo ago
oh okay, so yeah you still have to use start docker manually if you don't have systemd sudo dockerd otherwise install systemd, or just use the coder/enterprise-base image as your base image
anubis
anubisOP4mo ago
Oh my god, never thought about it... I will try when i get in the office. Will update you. Thank you. Issue got resolved. Thank you @Phorcys @Phorcys I am trying to use the codercom/enterprise-base:ubuntu but i get the same error if i dont start docker manually and when i run systemctl i get the following error:
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
I run it with the following command: sudo docker run --runtime=sysbox-runc -it --privileged codercom/enterprise-base:ubuntu
深雪
深雪4mo ago
add dockerd & in terraform config with log redirection systemd wont work normally in container
anubis
anubisOP4mo ago
if i run the official sysbox image with systemd and docker (nestybox/ubuntu-bionic-systemd-docker) then it works fine (both docker and systemctl but i have to login as a user. If i add the part to add the coder user then it fails. Also my biggest confusion comes from the documentation that says that you can have systemd in docker but only refers to the Kubernetes deployment. https://coder.com/docs/templates/docker-in-workspaces#systemd-in-docker
Docker in workspaces - Coder Docs
Use Docker inside containerized templates
From An unknown user
From An unknown user
Phorcys
Phorcys4mo ago
it will with Sysbox
Phorcys
Phorcys4mo ago
GitHub
sysbox/docs/quickstart/systemd.md at master · nestybox/sysbox
An open-source, next-generation "runc" that empowers rootless containers to run workloads such as Systemd, Docker, Kubernetes, just like VMs. - nestybox/sysbox
深雪
深雪4mo ago
oh yeah? i am using sysbox too, but i am just starting the daemon in the terraform file see this https://pastebin.com/AwcBiH3L
Pastebin
terraform { required_providers { coder = { source = "coder...
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
深雪
深雪4mo ago
my Dockerfile
FROM ubuntu

RUN apt-get update \
&& apt-get install -y nodejs npm python3 python3-pip openjdk-17-jdk maven \
curl \
git \
golang \
sudo \
vim \
wget \
build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev \
ca-certificates curl iputils-ping

RUN curl -sSL https://get.docker.com/ | sh

RUN rm -rf /var/lib/apt/lists/*


ARG USER=coder
RUN useradd -G sudo,docker --no-create-home --shell /bin/bash ${USER} \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \
&& chmod 0440 /etc/sudoers.d/${USER}
USER ${USER}
RUN sudo npm i -g n
RUN sudo n lts
WORKDIR /home/${USER}
FROM ubuntu

RUN apt-get update \
&& apt-get install -y nodejs npm python3 python3-pip openjdk-17-jdk maven \
curl \
git \
golang \
sudo \
vim \
wget \
build-essential libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev \
ca-certificates curl iputils-ping

RUN curl -sSL https://get.docker.com/ | sh

RUN rm -rf /var/lib/apt/lists/*


ARG USER=coder
RUN useradd -G sudo,docker --no-create-home --shell /bin/bash ${USER} \
&& echo "${USER} ALL=(ALL) NOPASSWD:ALL" >/etc/sudoers.d/${USER} \
&& chmod 0440 /etc/sudoers.d/${USER}
USER ${USER}
RUN sudo npm i -g n
RUN sudo n lts
WORKDIR /home/${USER}
anubis
anubisOP4mo ago
yes i did the same in the end, but cant get systemd to work. when i use the codercom image it doesnt start and if i use the sysbox image i need to use the admin account
深雪
深雪4mo ago
i assue u mean u need sudo or su root to use docker if you check my dockerfile, the coder user is added to the docker group RUN useradd -G sudo,docker --no-create-home --shell /bin/bash ${USER} \ in this way, you dont need sudo or root to run docker commands
anubis
anubisOP4mo ago
No, I have the same setup as you do now. That works fine. Docker works as expected. The issue is that systemd wont start and will give an error about the user if i use the codercom image. If i use the sysbox image it works fine but only with the admin:admin user
Phorcys
Phorcys4mo ago
i don't have an immediate answer as i've never tried it but yeah for now you can just start dockerd manually i'll play around with it to see how we can have systemd-in-docker working with Coder
深雪
深雪4mo ago
whats the error if u run systemctl with not admin acc? useradd --create-home --shell /bin/bash coder && echo "admin:admin" | chpasswd && adduser admin sudo docker try this in dockerfile
anubis
anubisOP4mo ago
that is the error with the codercom image.
No description
深雪
深雪4mo ago
hm, i got this error too same with sudo what did u do to make systemctl work with sudo?
anubis
anubisOP4mo ago
i havent managed to get it work. the only case where it works is if you use this image https://github.com/nestybox/dockerfiles/blob/master/ubuntu-bionic-systemd/Dockerfile . The issue is that if i add the part for creating a user (instead of using the default admin:admin) then i get errors again.
GitHub
dockerfiles/ubuntu-bionic-systemd/Dockerfile at master · nestybox/d...
Dockerfiles repository. Contribute to nestybox/dockerfiles development by creating an account on GitHub.

Did you find this page helpful?