65
83

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を振る

Last updated at Posted at 2017-09-10

概要

Apacheコンテナなどで、Virtualhostで複数のサイトを構築している場合、
各サイトへ指定のドメインにてリクエストする場合に、固定IPにしたくて
調べた結果をメモしておく。

ネットワークを追加する

compose fie version 2 の場合、ネットワークを追加することで対応できそうです。
また、version 2 の場合、linksの設定はなくても動くようなので削除してみる。

docker-compose.yml
version: '2'
services:
 app:
  image: busybox
  container_name: 'app'
  volumes:
   - ../www:/var/www
   - ./logs/httpd:/usr/local/apache2/logs
  networks:
    app_net:
      ipv4_address: 172.16.238.2

 mysql:
  image: reflet/debian8-mysql55:1.0
  container_name: 'mysql'
  env_file: .env.mysql
  ports:
   - '3306:3306'
  volumes:
   - ./initdb.mysql:/docker-entrypoint-initdb.d/
   - mysql-data:/var/lib/mysql
  networks:
    app_net:
      ipv4_address: 172.16.238.3

 postgres:
  image: reflet/debian8-postgres91:1.1
  container_name: 'postgres'
  env_file: .env.postgres
  volumes:
      - ./initdb.postgres:/docker-entrypoint-initdb.d/
      - postgres-data:/var/lib/postgresql/data
  ports:
      - "5432:5432"
  networks:
    app_net:
      ipv4_address: 172.16.238.4

 php:
  image: reflet/debian8-php56:1.5
  container_name: 'php'
  ports:
   - '9000:9000'
  volumes:
   - ./php.ini:/usr/local/etc/php/php.ini
   - ./php-ssmtp.conf:/etc/ssmtp/ssmtp.conf
  volumes_from:
   - app
  extra_hosts:
   - "www.example.com:172.16.238.6"
  networks:
    app_net:
      ipv4_address: 172.16.238.5

 httpd:
  image: reflet/debian8-httpd:1.6
  container_name: 'httpd'
  ports:
   - '80:80'
   - '443:443'
  volumes:
   - ./virtualhost:/usr/local/apache2/conf.d/virtualhost/
  volumes_from:
   - app
  networks:
    app_net:
      ipv4_address: 172.16.238.6

volumes:
  postgres-data:
    driver: local
  mysql-data:
    driver: local

networks:
  app_net:
    driver: bridge
    ipam:
     driver: default
     config:
       - subnet: 172.16.238.0/24
         gateway: 172.16.238.1

参考サイト

65
83
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
65
83

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?