5

Someone asked the same question here - the problem is that it relates to version 2 which I am not using. Is it meanwhile possible to define a static subnet and a static IP address for each started container with docker-compose within the docker-compose.yml file?

manifestor
  • 2,473

1 Answers1

7

Use the following docker-compose.yml in order to start your containers in a predefined network with static IPv4 addresses:

version: '3.5'
services:
  service1:
  image: service1:latest
  networks:
    service1_net:
      ipv4_address: 172.22.0.100
networks:
  service1_net:
    ipam:
      driver: default
      config:
        - subnet: 172.22.0.0/16
manifestor
  • 2,473
  • Works fine for me, also with v. 3.1. Indentation missing after service1: but cannot edit and indent, because the changes are only 4 spaces, but S.O. requires edits to be 6 characters at least. — I think the driver: ... line should be directly after service1_net:? – KajMagnus Jan 09 '19 at 11:41