34
Help us understand the problem. What are the problem?

More than 3 years have passed since last update.

posted at

dockerのコンテナに固定IPを振る(compose file version 3の注意点)

docker-composeで固定IPを割り振って起動を試みた

doncker-compose.yml

version: '3.3'

services:

  wordpress:
    image: wordpress
    restart: always
    ports:
      - 8080:80
    networks:
      app_net:
        ipv4_address: 172.30.0.3
    environment:
      - WORDPRESS_DB_PASSWORD
      - TZ

  mysql:
    image: mariadb-10.3.8:05
    build: .
    restart: always
    networks:
      app_net:
        ipv4_address: 172.30.0.2
    environment:
      - MYSQL_ROOT_PASSWORD=${WORDPRESS_DB_PASSWORD}
      - TZ

networks:
  app_net:
    driver: bridge
    ipam:
     driver: default
     config:
       - subnet: 172.30.0.0/24
         gateway: 172.30.0.1

docker-compose upしたところERRORが発生

$ sudo docker-compose up -d
RROR: The Compose file './docker-compose.yml' is invalid because:
networks.app_net.ipam.config value Additional properties are not allowed ('gateway' was unexpected)

調査してみると

compose file version3よりgatewayの項目は指定できなくなっているので
コメントアウトして再度docker-compose up

docker-compose.yml
version: '3.3'

services:
--------------------------省略-------------------
networks:
  app_net:
    driver: bridge
    ipam:
     driver: default
     config:
       - subnet: 172.30.0.0/24
#         gateway: 172.30.0.1    <-----コメントアウト
$ sudo docker-compose up -d
Creating compose_wordpress_wordpress_1 ... done
Creating compose_wordpress_mysql_1     ... done

今度はうまくいきました。

参考サイト

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
34
Help us understand the problem. What are the problem?