How to set network in docker-compose.yml?

Hi all,
I am running Docker-CE version 20.10.12 and docker-compose version 1.29.2
I deployed the first Apache docker (Docker Hub) after that I created “docker-compose.yml” file.

Here my settings:

web:
  image: 'httpd'
  ports:
    - '80:80'
    - '443:443'
  volumes:
    - '/mnt/disk_docker/:/usr/local/apache2/htdocs/'

I created a custom bridge network.

user@docker:~$ docker network inspect mynet
[
    {
        "Name": "mynet",
        "Id": "93f908811eb8e4aaff64ee7a6eb87df80b827f3920d34d17e1ab88724faa3646",
        "Created": "2022-02-22T16:33:50.586058181Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": false,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "192.168.1.0/24",
                    "IPRange": "192.168.1.0/25",
                    "Gateway": "192.168.1.1"
                }
            ]
        },
        "Internal": false,
        "Attachable": false,
        "Ingress": false,
        "ConfigFrom": {
            "Network": ""
        },
        "ConfigOnly": false,
        "Containers": {
            "fca7c7bfb2ce904a70ad3a4ef9d036f1ca91c9ec0e6974e1a022e0c3bf0a12ff": {
                "Name": "connect_web_1",
                "EndpointID": "a17ac828b7f57b4fc89e7824356d2b7b2e68fe1c6aaecc11e242f2d5c8db8718",
                "MacAddress": "02:42:c0:a8:01:02",
                "IPv4Address": "192.168.1.2/24",
                "IPv6Address": ""
            }
        },
        "Options": {},
        "Labels": {}
    }
]

I tried to set, inside docker-compose.yml file network settings without success.
I need to set static IP to HTTPD docker and assign this HTTPD docker inside “mynet” bridge network.

I tried to edit docker-compose.yml file without success…
How can I do using “docker-compose.yml”?

Thanks a lot
Federico

Hi :slight_smile:

Try this

version: '2'
services:
  web:
    image: 'httpd'
    ports:
      - '80:80'
      - '443:443'
    volumes:
      - '/mnt/disk_docker/:/usr/local/apache2/htdocs/'
    networks:
      mynet:
        ipv4_address: 192.168.1.3
        
networks:
  mynet:
    external: true
    name: mynet

Hi @terpz,
Thanks a lot for your suggestion!

I tried and it worked fine.
I tried to set “version: 3.9” and it works fine!

Best regards
Federico