[英]Assigning /32 ip addr to containers with docker compose Ubuntu 20.04
as you might quickly notice, I'm not a.network nor a docker guru.您可能很快就会注意到,我既不是 a.network 也不是 docker 大师。 I appreciate all help big time!
我感谢所有的帮助!
I'm trying to run a two applications in two different docker container using docker-compose. I managed to run 1 application using the host.network.我正在尝试使用 docker-compose 在两个不同的 docker 容器中运行两个应用程序。我设法使用 host.network 运行 1 个应用程序。 Great success, at least for half of my goal.
非常成功,至少完成了我目标的一半。 Every container needs to be mapped to a specific IP address.
每个容器都需要映射到特定的 IP 地址。 If you wonder why, it's because the services in the containers will be accessed by other applications on the www on a specific port.
如果你想知道为什么,那是因为容器中的服务将被特定端口上 www 上的其他应用程序访问。 But every container uses the same port for this communication.
但是每个容器都使用相同的端口进行此通信。 To give you a more visual idea of the desired setup, here's a visual:
为了让您更直观地了解所需的设置,这里有一个视觉效果:
For service AI linked the container to the host.network.对于服务 AI,将容器链接到 host.network。 My the docker-compose.yml looks like this:
我的 docker-compose.yml 看起来像这样:
version: "3.8"
services:
shell:
image: "${MAIN_IMAGE}"
container_name: mnm_shell
network_mode: host
pid: host
volumes:
- "mnms:/home/mnms"
entrypoint: [ "bash" ]
env_file:
- "./.env"
After lots of research I found many articles describing how to make a macvlan with a private address su.net but I did not find any article describing how to link one (or more) /32.networks to specific containers.经过大量研究,我找到了许多描述如何使用私有地址 su.net 制作 macvlan 的文章,但我没有找到任何描述如何将一个(或多个)/32.networks 链接到特定容器的文章。
Any help, guidance, examples are welcome.欢迎任何帮助、指导和示例。 Thanks in advance!
提前致谢!
It's been 6 months since you posted, hopefully you will still find this useful.自您发布以来已经 6 个月了,希望您仍然会发现它有用。
You can do what your asking by creating a custom docker.network which uses the macvlan
driver.您可以通过创建使用
macvlan
驱动程序的自定义 docker.network 来完成您的要求。 Relevant docker reference: https://docs.docker.com.network.network-tutorial-macvlan/#bridge-example docker相关参考: https://docs.docker.com.network.network-tutorial-macvlan/#bridge-example
First create the.network:首先创建.network:
docker network create -d macvlan \
--subnet=50.50.50.0/24 \
--gateway=50.50.50.1 \
-o parent=eth0 \
my-macvlan-network
Once created you can reference it in your docker-compose files.创建后,您可以在 docker-compose 文件中引用它。 I've adapted your original example here:
我在这里改编了你原来的例子:
version: "3.8"
networks:
my-macvlan-network:
external: true
services:
shell:
image: "${MAIN_IMAGE}"
container_name: mnm_shell
networks:
macvlan1:
ipv4_address: 50.50.50.201
volumes:
- "mnms:/home/mnms"
entrypoint: [ "bash" ]
env_file:
- "./.env"
Note: host
.networking has been removed.注意:
host
.networking 已被删除。
A few things to note:有几点需要注意:
macvlan
IP's, however your docker host cannot. macvlan
IP,但是您的 docker 主机不能。 See the following link for a way to fix that: https://github.com/sarunas-zilinskas/docker-compose-macvlan#enable-host-to-container.networking I'm using this technique on a linux host with PiHole and Gitea containers.我在带有 PiHole 和 Gitea 容器的 linux 主机上使用这种技术。 Pihole wants port 53 (DNS) and gitea wants port 22 (SSH).
Pihole 需要端口 53 (DNS) 而 gitea 需要端口 22 (SSH)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.