icksde
icksde

Reputation: 287

How to change dockers default network?

I created a new docker network ( macvlan https://docs.docker.com/engine/userguide/networking/get-started-macvlan/ )

How is it possible to tell docker to use this network as default (instead of bridge) when creating new container? I want to spare the --net for every new container.

Upvotes: 5

Views: 13292

Answers (3)

Keivan
Keivan

Reputation: 1779

If you use docker-compose, you can use networks-key in yml-file. The following specifies mongo to use "pinguine" as default network:

version: '3.1'
services:

  mongo:
    image: mongo
    restart: always
    environment:
      MONGO_INITDB_ROOT_USERNAME: root
      MONGO_INITDB_ROOT_PASSWORD: example
    networks:
      - project-network

networks:
  project-network:
    name: pinguine

Upvotes: 0

Roman
Roman

Reputation: 21845

Docker provides different network drivers like bridge, host, overlay, and macvlan. bridge is the default.

To change your default network driver:

  • Edit or create config file for docker daemon:

    # nano /etc/docker/daemon.json
    

    Add lines:

    {
      "default-address-pools":
        [
          {"base":"10.10.0.0/16","size":24}
        ]
    }
    

    Restart dockerd:

    # service docker restart
    
  • Create a new network with the new network driver by using the --driver or -d parameter with your docker network create command

  • Run your Docker image with the --network parameter to use your newly-created network.

    $ docker network create foo
    $ docker network inspect foo | grep Subnet
                "Subnet": "10.10.1.0/24"
    

Upvotes: -2

kstromeiraos
kstromeiraos

Reputation: 5037

Create or edit file /etc/docker/daemon.json and add the following configuration.

{
    "bridge": "my_network"
}

This way my_network would be used by default.

Upvotes: -2

Related Questions