Building and starting of my docker-compose project fails with the error:
ERROR: failed to solve: process "/bin/sh -c npm install" did not complete successfully: network bridge not found
my docker-compose.yml
file only contains:
version: '3'
services:
myapp:
build:
context: .
dockerfile: Dockerfile
restart: always
volumes:
- ./data:/app/data
ports:
- 3000:3000
for security reason the /etc/docker/daemon.json
doesn’t enable a network bridge by default:
{
"ipv6": true,
"iptables": true,
"bridge": "none",
"bip": "",
"default-address-pools": [
...
],
...
Adding the following line to the docker-compose.yml doesn’t solve the issue:
network_mode: host
What is the right way to do?
In order to have the network bridge enabled during the build process, you have to use network: host
within the build section of the docker-compose.yml
:
version: '3'
services:
myapp:
build:
context: .
dockerfile: Dockerfile
network: host
restart: always
volumes:
- ./data:/app/data
ports:
- 3000:3000
To also have the bridge available during container execution you would use network_mode: host
in the myapp
section. Like this:
version: '3'
services:
myapp:
build:
context: .
dockerfile: Dockerfile
network: host
restart: always
volumes:
- ./data:/app/data
ports:
- 3000:3000
network_mode: host
Further reference can be found in the Compose Build Specification and the Services top-level elements documentation.