0

How do i assign static ip address to each container in the docker-compose file.

error: Creating network "dockercompose7405404752525846881_app_net" with driver "default"plugin not found.

The solusion has two projects, a web front-end and a web-api back-end. The back-end is accessed through angular.js

Project builds and runs out side of docker, and runs inside docker.

The problem is i need to set static ipaddress in the docker-compose file so i can manage the compunication between the frontend and backend (remebering it's angular that needs to know the ip of the webapi).

This is my sanitised docker-compose file:

version: '2.1'

services:
  backend.api:
    image: backend.api
    ports:
      - "80:80"
    build:
      context: .\backend.API
      dockerfile: Dockerfile
    networks:
      app_net:
        ipv4_address: 111.111.1.200 


  frontend:
    image: frontend
    env_file: 
      - .\frontend\config.env
    ports:
      - "80:80"
    build:
      context: .\frontend
      dockerfile: Dockerfile
    networks:
       app_net:
        ipv4_address: 111.111.1.210       

networks:
   app_net:
     driver: default
     ipam:
      driver: default
      config:
       - subnet: 111.111.1.0/24 

The error msg I'm getting is as follows:

Creating network "dockercompose7405404752525846881_app_net" with driver "default"plugin not found.

I have tried version 3 ver 2 and ver 2.1

veben
  • 19,637
  • 14
  • 60
  • 80
Jenco. D
  • 1
  • 1
  • 3
  • If I understand correctly, you want static ips to allow the frontend and backend services to communicate? – yamenk Jan 29 '18 at 16:06
  • If you want to communicate with your services you can use the name service no more. – julian salas Jan 29 '18 at 16:10
  • Thats correct Yamenk, I need the server ip to be added to the code confg of the frontend so when the website loads on my computer my computer knows how to compunicate with the api. (this is becouse the javascript is doing all the coms) hope that make sence? – Jenco. D Jan 29 '18 at 16:16
  • Thanks for commenting julian, could you give any gudence on how i would do this at an implementation level?? – Jenco. D Jan 29 '18 at 16:47
  • If both containers are in the same network you can refer to each of them by their service name. For example if you have a database you can link your backend to it and in your backend configuration file refer to the database by its name (instead of the database ip) – Yonah Dissen Jan 29 '18 at 17:03
  • https://stackoverflow.com/questions/38088279/communication-between-multiple-docker-compose-projects – Yonah Dissen Jan 29 '18 at 17:11

1 Answers1

-1

I’m hoping this helps someone else having the same problem. "THIS IS FOR WINDOWS DOCKER CONTAINERS"

I finally found the correct way to achieve setting static ip’s on my containers while in visual studio using the Docker-Compose file..

The key thing is you need to create a network manually first

docker network create -d nat --subnet=192.168.1.0/24 --gateway=192.168.1.254 app_net

When you execute this line in PowerShell you please remember to change the network name and the ipaddress to suit your purposes

docker network create -d nat --subnet=<subnet ip>/<end renage> --gateway=<gateway ip> <network name>

The Docker-compose file

version: '3.2'

services:
  backend.api:
    image: backend.api
    build:
      context: .\backend.API
      dockerfile: Dockerfile
    networks:
       app_net:
        ipv4_address: 111.111.1.210        

  FRONTEND:
    image: FRONTEND
    env_file: 
      - .\FRONTEND\config.env
    build:
      context: .\FRONTEND
      dockerfile: Dockerfile
    networks:
       app_net: 
        ipv4_address: 111.111.1.220


networks:
   app_net:
     external: true
Jenco. D
  • 1
  • 1
  • 3
  • Looking at the IP addresses - these two containers are in the same network which means the better solution would be to use the service names instead of the static IP addresses. These services names from any applications/tool within containers in the same network. – nashter Apr 02 '21 at 09:32