Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Docker compose Custom Network to realize fixed Container ip address

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/02 Report--

Due to the default bridge bridging network, the ip address will be changed when the container is restarted. In some scenarios, we want to fix the container IP address.

Docker-compose is an orchestration tool for docker that creates networks, containers, etc., relative to command mode. Using configuration files is relatively convenient and traceable.

Paste the docker-compose.yml file directly

Version: '2'services: nginx: image: nginx:1.13.12 container_name: nginx restart: always tty: true networks: extnetwork: ipv4_address: 172.19.0.2 networks: extnetwork: ipam: config:-subnet: 172.19.0.0 16 gateway: 172.19.0.1

Description:

Gateway is the gateway address subnet is the network number range extnetwork is a custom network name

In the above configuration, our nginx container has a fixed ip of 172.19.0.2

Example, custom network mode:

Version: '2'services: nginx: image: nginx:1.13.12 container_name: nginx restart: always networks: extnetwork: ports:-80:80 volumes: -' / nginx/conf.d:/etc/nginx/conf.d' nginx2: image: nginx:1.13.12 container_name: nginx2 restart: always networks: extnetwork: ipv4_address: 172.19.0.2 Db: image: mysql:5.7 container_name: db volumes:-/ var/lib/mysql:/var/lib/mysql restart: always networks: extnetwork: ports:-3306 environment: MYSQL_ROOT_PASSWORD: wordpress MYSQL_DATABASE: wordpress MYSQL_USER: wordpress MYSQL_PASSWORD: wordpress wordpress: image: wordpress:latest container_name: wordpress depends_on:-db ports: -"8000 environment 80" restart: always networks: extnetwork: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_NAME: wordpress WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpressnetworks: extnetwork: ipam: config:-subnet: 172.19.0.0 16 gateway: 172.19.0.1

The above is the whole content of this article, I hope it will be helpful to your study, and I also hope that you will support it.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report