<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Selhosted on Mike Bell - Blog &amp; Stuff</title><link>https://mikebell.io/categories/selhosted/</link><description>Recent content in Selhosted on Mike Bell - Blog &amp; Stuff</description><generator>Hugo -- gohugo.io</generator><language>en</language><managingEditor>hello@mikebell.io (Mike Bell)</managingEditor><webMaster>hello@mikebell.io (Mike Bell)</webMaster><copyright>© 2026 Mike Bell</copyright><lastBuildDate>Fri, 14 Feb 2025 20:29:52 +0000</lastBuildDate><atom:link href="https://mikebell.io/categories/selhosted/index.xml" rel="self" type="application/rss+xml"/><item><title>Building docker image with Forgejo Actions</title><link>https://mikebell.io/posts/building-docker-image-forgejo-actions/</link><pubDate>Fri, 14 Feb 2025 20:29:52 +0000</pubDate><author>hello@mikebell.io (Mike Bell)</author><guid>https://mikebell.io/posts/building-docker-image-forgejo-actions/</guid><description>
&lt;p>aka how I nearly went crazy trying to figure out how to build docker images in Forgejo Actions.&lt;/p>
&lt;p>With the default setup from &lt;a
href="https://forgejo.org/docs/latest/admin/runner-installation/#oci-image-installation"
target="_blank"
>here&lt;/a> you can get up and running with foregjo actions &lt;em>but&lt;/em> it won&amp;rsquo;t allow you to build docker images inside your workflows.&lt;/p>
&lt;p>When I tried to build a docker image in a workflow I kept getting the following:&lt;/p>
&lt;pre tabindex="0">&lt;code>ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
::error::buildx failed with: ERROR: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?
&lt;/code>&lt;/pre>&lt;p>It&amp;rsquo;s quite a common error and something that should be easy to fix but when you throw docker-in-docker in to the mix it becomes way more complex.&lt;/p>
&lt;p>To cut a long story short I found a &lt;a
href="https://code.forgejo.org/forgejo/runner/issues/153#issuecomment-5824"
target="_blank"
>comment&lt;/a> with a link to &lt;a
href="https://code.forgejo.org/forgejo/runner/src/branch/main/examples/docker-compose/compose-forgejo-and-runner.yml"
target="_blank"
>this&lt;/a> example which was confirmed to be working, after a few tweaks I came up with the docker compose below. I&amp;rsquo;ve removed the need to be running forgejo already (I have set in a separate compose) and updated the base image.&lt;/p>
&lt;pre tabindex="0">&lt;code># Copyright 2024 The Forgejo Authors.
# SPDX-License-Identifier: MIT
#
# Create a secret with:
#
# openssl rand -hex 20
#
# Replace all occurences of {SHARED_SECRET} below with the output.
#
# NOTE: a token obtained from the Forgejo web interface cannot be used
# as a shared secret.
#
# Replace {ROOT_PASSWORD} with a secure password
#
volumes:
docker_certs:
services:
docker-in-docker:
image: code.forgejo.org/oci/docker:dind
hostname: docker # Must set hostname as TLS certificates are only valid for docker or localhost
privileged: true
environment:
DOCKER_TLS_CERTDIR: /certs
DOCKER_HOST: docker-in-docker
volumes:
- docker_certs:/certs
restart: unless-stopped
runner-register:
image: code.forgejo.org/forgejo/runner:6.2.2
links:
- docker-in-docker
environment:
DOCKER_HOST: tcp://docker-in-docker:2376
volumes:
- ./data:/data
user: 0:0
command: &amp;gt;-
bash -ec &amp;#39;
while : ; do
forgejo-runner create-runner-file --connect --instance https://code.remotelab.uk --name runner --secret {SHARED_SECRET} &amp;amp;&amp;amp; break ;
sleep 1 ;
done ;
sed -i -e &amp;#34;s|\&amp;#34;labels\&amp;#34;: null|\&amp;#34;labels\&amp;#34;: [\&amp;#34;docker-cli:docker://code.forgejo.org/oci/docker:cli\&amp;#34;,\&amp;#34;node-bookworm:docker://code.forgejo.org/oci/node:20-bookworm\&amp;#34;]|&amp;#34; .runner ;
forgejo-runner generate-config &amp;gt; config.yml ;
sed -i -e &amp;#34;s| level: info| level: debug|&amp;#34; config.yml ;
sed -i -e &amp;#34;s|network: .*|network: host|&amp;#34; config.yml ;
sed -i -e &amp;#34;s|^ envs:$$| envs:\n DOCKER_HOST: tcp://docker:2376\n DOCKER_TLS_VERIFY: 1\n DOCKER_CERT_PATH: /certs/client|&amp;#34; config.yml ;
sed -i -e &amp;#34;s|^ options:| options: -v /certs/client:/certs/client|&amp;#34; config.yml ;
sed -i -e &amp;#34;s| valid_volumes: \[\]$$| valid_volumes:\n - /certs/client|&amp;#34; config.yml ;
chown -R 1000:1000 /data
&amp;#39;
runner-daemon:
image: code.forgejo.org/forgejo/runner:6.2.2
links:
- docker-in-docker
environment:
DOCKER_HOST: tcp://docker:2376
DOCKER_CERT_PATH: /certs/client
DOCKER_TLS_VERIFY: &amp;#34;1&amp;#34;
volumes:
- ./data:/data
- docker_certs:/certs
restart: &amp;#39;unless-stopped&amp;#39;
command: &amp;gt;-
bash -c &amp;#39;
while : ; do test -w .runner &amp;amp;&amp;amp; forgejo-runner --config config.yml daemon ; sleep 1 ; done
&amp;#39;
&lt;/code>&lt;/pre>&lt;p>Hopefully this helps anyone else who comes across this issue.&lt;/p>
&lt;p>Thanks for reading via RSS!&lt;/p>
&lt;p>Send me a message on &lt;a href="https://remotelab.uk/mikebell">Mastodon&lt;/a> or &lt;a href="mailto:hello@mikebell.io">email me&lt;/a>&lt;/p></description></item></channel></rss>