36
33

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

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

Posted at

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

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

参考サイト

36
33
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
36
33

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?