您好,登錄后才能下訂單哦!
由于默認的bridge橋接網絡,重啟容器后會改變ip地址。在一些場景下我們希望固定容器IP地址。
docker-compose是docker的一個編排工具,相對于命令模式創建網絡,容器等。使用配置文件相對來說更方便,可追溯問題。
直接粘貼docker-compose.yml文件
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
說明:
上面配置中我們的nginx容器固定ip為172.19.0.2
示例,自定義網絡模式:
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: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:80" restart: always networks: extnetwork: environment: WORDPRESS_DB_HOST: db:3306 WORDPRESS_DB_NAME: wordpress WORDPRESS_DB_USER: wordpress WORDPRESS_DB_PASSWORD: wordpress networks: extnetwork: ipam: config: - subnet: 172.19.0.0/16 gateway: 172.19.0.1
以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持億速云。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。