gpt4 book ai didi

Docker-Compose v3-静态IP

转载 作者:行者123 更新时间:2023-12-04 14:39:24 31 4
gpt4 key购买 nike

我试图在我的docker-compose v3文件上设置一个静态IP,但是..我不能。
每次设置时,都无法连接到该网页。
我正在获取ERR_ADDRESS_UNREACHABLE
这是我的配置:

# docker-compose.yml
version: '3'
services:
web:
build: ./etc/nginx
ports:
- "90:80"
volumes:
- "./etc/ssl:/etc/ssl"
depends_on:
- php
- database
php:
build: ./etc/php
ports:
- 9000:9000
links:
- database:mysqldb
volumes:
- "./etc/php/php.ini:/usr/local/etc/php/conf.d/php.ini"
- ${APP_PATH}:/var/www/symfony
database:
image: mysql
environment:
MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
MYSQL_DATABASE: ${MYSQL_DATABASE}
MYSQL_USER: ${MYSQL_USER}
MYSQL_PASSWORD: ${MYSQL_PASSWORD}
ports:
- 3300:3306
volumes:
- "./data/db/mysql:/var/lib/mysql"


# docker-compose.override.yml
version: '3'
services:
web:
networks:
test:
ipv4_address: '10.1.0.100'

networks:
test:
ipam:
driver: default
config:
- subnet: 10.1.0.0/24

最佳答案

应该是这样的:

services:
web:
networks:
test:
ipv4_address: 10.1.0.100

networks:
test:
driver: bridge
ipam:
driver: default
config:
- subnet: 10.1.0.0/24

就我而言,我将 networks部分放在 services之前。

更新:

最终,我最终像这样使用外部网络:
docker network create --subnet 10.5.0.0/24 local_network_dev
然后在任何docker-compose中,您都可以像这样使用它:
version: '3.2'
networks:
default:
external:
name: local_network_dev

和图像的内部:
  web:
networks:
default:
ipv4_address: 10.5.0.11

关于Docker-Compose v3-静态IP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46461977/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com