7
8

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 3 years have passed since last update.

docker-composeで固定IPアドレス指定

Posted at

Docker便利ですよね。

ソフト開発という荒波に、Docker艦隊は強大な味方です。
ただし、指示書がなければこの優秀な艦隊は動いてくれません。

今日はその通達文、docker-composeのTips

コンテナに固定IPアドレスを振りたい場合は以下のように指定する。

version: "3"
services:

  main-server:
    restart: always
    image: main_server:v0.0.1
    container_name: "main-server"
    ports:
      - "8080:80"
    networks:
      app_net:
        ipv4_address: 172.30.0.2

  sub-server:
    restart: always
    image: sub_server:v0.0.1
    container_name: "sub-server"
    ports:
      - "8080:80"
    networks:
      app_net:
        ipv4_address: 172.30.0.3

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

内部ネットワークドライバとして、bridgeを指定して使っていきます。

公式ドキュメント
https://docs.docker.com/compose/compose-file/compose-file-v3/#ipv4_address-ipv6_address

現場からは以上です。

7
8
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
7
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?