Here are the commands to run on the host. You only need the name of the container to perform the setup. In my example I’ll use mycontainer.
lxc config device add mycontainer myport80 proxy listen=tcp:0.0.0.0:80 connect=tcp:127.0.0.1:80
lxc config device add mycontainer myport443 proxy listen=tcp:0.0.0.0:443 connect=tcp:127.0.0.1:443
What we do here is:
We add a proxy device on container mycontainer, giving it an arbitrary name (myport80).
We set it up to listen on all (0.0.0.0) network interfaces on the host, port 80. You can change the IP address to something more specific, if you want to.
We set it up to make connections to the container mycontainer on the 127.0.0.1 (localhost) interface at port 80. PREVIOUS GUIDES SUGGESTED TO USE localhost. DOES NOT WORK ANYMORE; PLEASE USE 127.0.0.1 INSTEAD!
To verify that LXD is listening on port 80 (http), run
$ sudo lsof -i -n | grep http
lxd 2157 root 5u IPv6 668213 0t0 TCP *:http (LISTEN)
lxd 2157 root 8u IPv6 668213 0t0 TCP *:http (LISTEN)
To remove a proxy device, run
lxc config device remove mycontainer myport80

本文介绍如何在LXD中为容器设置端口代理,包括HTTP和HTTPS端口的监听与连接配置,以及如何验证LXD是否正在监听指定端口,并提供了移除代理设备的方法。
192

被折叠的 条评论
为什么被折叠?



