Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I set up a docker-compose configuration with no networks?

I use Docker Compose to configure some Dockerised batch jobs. These jobs pull some data from external databases and then save data back to other databases. The jobs never interact directly with each other. They do not expose any ports or run any servers.

I would like to switch off Docker networking.

By default, docker-compose creates a network for each configuration. Is there a way to supress this so that compose starts running the container without bothering to create any network?

like image 424
Salim Fadhley Avatar asked Oct 20 '25 10:10

Salim Fadhley


1 Answers

If you bothering the sole create/destroy process of the network you can create a network once and use it every time you spin the compose.

networks:
  default:
    external: true
    name: whatevernameyougaveit

In addition there is a docker built-in network called None, which disables networks completely for a container joining that. Maybe you already have seen it with docker network ls along with host

services:
  service:
   network_mode: none

If all services using a network_mode host or none, compose will suppress the creation of the default network..

Edit: One (including me) might have the idea to implement it like that to get rid of the network_mode setting for each service:

networks:
  default:
    external: true
    name: none

But then compose thinks it is actually a network and tries to set the network aliases which leads to an error: network-scoped alias is supported only for containers in user defined networks. Same applies if you try to add the other pre-configured networks like that.

like image 190
araisch Avatar answered Oct 21 '25 23:10

araisch



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!