Raspbian Docker-Compose Static-IP not working

Hello everyone,

i have only been working with Docker for a short time. Currently, I’m trying to create an service with openvpn. To create the service I used docker-compose with version 2.4 (defined in the Yaml).

For routing purposes I want to assign a static-ip to the container. The network is a bridge-network with the following specifications:

  • subnet: 172.16.128.0/17
  • ip-address: 172.16.128.1
  • ip-range: 172.16.128.0/17
  • gateway: 172.16.255.254

When I execute the command “ip addr show” in the container by the Dockerfile, it gaves me the ip “172.17.x.x” as output and not the static ip. A ping is also not successfull. But the network is successfully created.

My docker-compose.yaml:

version: "2.4"
networks:
    extern:
            driver: bridge 
            name: bridge_extern
            ipam:
                    driver: default 
                    config:
                            - subnet: 172.16.128.0/17
                              ip_range: 172.16.128.0/17
                              gateway: 172.16.255.254
                              aux_addresses:
                                      openvpn-docker: 172.16.128.1
volumes:
    openvpn_pki:
            external: true
services:
    openvpn:
            build: .
            image: debian:latest
            hostname: openvpn-docker
            container_name: extern_openvpn
            dns:
                    - 8.8.4.4
            cap_add:
                    - NET_ADMIN
                    - NET_RAW
            ports:
                    - "1194:1194"
            networks:
                    extern:
                            ipv4_address: 172.16.128.1
            volumes:
                    - type: volume
                      source: openvpn_pki
                      target: /etc/openvpn/pki
                    - type: bind 
                      source: .
                      target: /media

Do you have an idea and can you please help me?

Thank you and best regards
Erik

Just a question rather than answering your question: did you use TAB for indentation? I understand this is not working and the space bar should be used instead (twice for one indentation)

Hi reneth,

thank you for your answer. Yes, I am using TAB for indentation, but it works fine.

A couple of hours ago I have solved the problem myself. When executing a dockerfile, which is be parameterized in an docker-compose yaml-file, for every RUN-command in the dockerfile, a container is starting. In conclusion, the options in the docker-compose yaml-file take affect afterwards, after the dockerfile was executed completly.

Best regards
Erik