Docker Compose Network

Updated . Posted . Visible to the public.

This example shows that how the static ip can be assigned to container and how to add another container network to a container. This can be done only for version 2 compose.

version: '2'

services:
  app:
    image: busybox
    command: ping www.google.com
    networks:
      app_net:
        ipv4_address: 10.0.0.10
  webapp:
    image: busybox
    command: ping www.yahoo.com
    network_mode: service:app
        

networks:
  app_net:
    driver: bridge
    ipam:
      driver: default
      config:
      - subnet: 10.0.0.0/24
        gateway: 10.0.0.1
     
version: '3.3'

networks:
  pwa_net:
    ipam:
      driver: default
      config:
      - subnet: 40.0.0.0/24
        gateway: 40.0.0.1
        
services:
  web-cont:
    image: registry.kemana.com/magento24_fpm74:1.0
    container_name: magentoent242-web-cont
    volumes:
      - /home/suresh/works/projects/magentoEnt242:/var/www/html   
   
    environment:
      SERVER_NAME: magentoent242.dev.local    
      USER_ID: 1000
   
    networks:
      pwa_net:
        ipv4_address: 40.0.0.10  
        
  mysql-cont:
    image: mysql:8.0      
    container_name: magentoent242-mysql-cont
   
    networks:
      pwa_net:
        ipv4_address: 40.0.0.11
       
    environment:
      MYSQL_ROOT_PASSWORD: root
      MYSQL_DATABASE: magentoent242
      MYSQL_USER: magentoent242
      MYSQL_PASSWORD: magentoent242       

  mailhog-cont:
    container_name: magentoent242-mailhog
    image: mailhog/mailhog
    
    networks:
      pwa_net:
        ipv4_address: 40.0.0.12
        
  elastic-cont:
    image: elasticsearch:7.12.1      
    container_name: magentoent242-elastic-cont
    
    environment:
      discovery.type: single-node
      bootstrap.memory_lock: "true"
      xpack.security.enabled: "false"
      xpack.ml.enabled: "true"
      ES_JAVA_OPTS: -Xms512m -Xmx512m
      
     
    networks:
      pwa_net:
        ipv4_address: 40.0.0.13 
     
  redis-cont:
    image: redis:6.0      
    container_name: magentoent242-redis-cont
    networks:
      pwa_net:
        ipv4_address: 40.0.0.14
    
vasan
Last edit
vasan
Keywords
docker, compose
Posted by vasan to vasan's deck (2016-11-30 04:28)