Thank @jarrodu for your answer. I don’t know how I can bind a service to an interface. Which configuration file I should modify?
Let me explain a little more what I am doing. I created this simple service as the following Sinatra service (app.rb):
require 'sinatra'
set :port, 80
get '/' do
'Hello world!'
end
I can run the service above with ruby app.rb, which by default creates a service on port 4567. In this case, I am also using the port 80, to be sure there is no filter on some uncommon ports.
This is the first time I have problems with accessing services from containers. Now, I launched two more containers from scratch, one with Debian and another with Ubuntu, to see if it was a problem in the container configuration. However, the result is the same. I also run the service on the host, which is accessible from the host itself.
I guess that there is a problem with the network between the host and the containers. However, I don’t see something special with the network. I just followed the predefined steps in lxd init when creating it.
I was able to reproduce what I was talking about. I am running Debian 12 as my host and I used a debian/12/cloud image for the container. I am using Incus 0.4.
So, in the container create an empty directory and an index.html file. Then,
caddy file-server --listen 0.0.0.0:8080 --root
the, you can curl from the host.
curl 10.128.128.123:8080
Now, try again with,
caddy file-server --listen 127.0.0.1:8080 --root
instead, and curl again from the host.
curl 10.128.128.123:8080
The first will connect, but the second will not.
If you can not reproduce my results, then you might want to try using Incus instead of lXD.
If you can reproduce my results, then you might want to use Incus instead of LXD, and figure out how to get Sinatra to bind to 0.0.0.0 instead of 127.0.0.1.
You are right! The first version works and the second version does not. Thank you so much. Also, thank you for telling me about caddy. By the way, I plan to migrate to Incus soon.