LXC/LXD端口映射到主机

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
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
LXC(Linux Containers)和LXD(Linux Container Daemon)是一种轻量级虚拟化技术,常用于在Linux系统中创建和管理容器。以下是一些常用的LXC/LXD配置: 1. 安装LXD:使用适合你的Linux发行版的包管理工具进行安装。 2. 初始化LXD:运行`sudo lxd init`命令来初始化LXD。在初始化过程中,你可以设置默认的存储池、网络设置、镜像源等。 3. 创建容器:使用`lxc launch`命令创建一个新容器。例如,要创建一个名为"mycontainer"的容器,可以运行`lxc launch images:ubuntu/20.04 mycontainer`。 4. 启动和停止容器:使用`lxc start`命令启动容器,例如`lxc start mycontainer`。使用`lxc stop`命令停止容器,例如`lxc stop mycontainer`。 5. 进入容器:使用`lxc exec`命令可以在容器内执行命令。例如,要在"mycontainer"容器内执行`ls`命令,可以运行`lxc exec mycontainer -- ls`。 6. 管理容器配置:使用`lxc config`命令可以管理容器的配置。例如,要查看容器的IP地址,可以运行`lxc config show mycontainer | grep ipv4.address`。 7. 管理网络:使用`lxc network`命令可以管理LXD网络。例如,要列出所有网络,可以运行`lxc network list`。 8. 导出和导入容器:使用`lxc export`命令可以将容器导出到一个文件。例如,要将"mycontainer"导出到"mycontainer.tar.gz"文件,可以运行`lxc export mycontainer mycontainer.tar.gz`。使用`lxc import`命令可以从导出文件导入一个容器。 这些是LXC/LXD的一些常用配置,还有其他更高级的配置和功能可供探索。你可以使用`lxc --help`命令或参考LXD的官方文档来获取更多详细信息。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值