I have a directory apkmirror-scraper-compose with the following structure:
.
├── docker-compose.yml
├── privoxy
│ ├── config
│ └── Dockerfil
Add
version: '3.7'
services:
web:
...
network_mode: bridge
Read about network_mode in the documentation.
Disclaimer: I am not very knowledgeable about Docker networking, but this did the trick for me. YMMV.
When I ran docker run my-image the networking gave me no problems, but when
I converted this command to a docker-compose.yml file, I got the same error
as the OP.
I read Arenim's answer and some other stuff on the internet that suggested to re-use an existing network.
You can find existing networks like this:
# docker network ls
NETWORK ID NAME DRIVER SCOPE
ca0415dfa442 bridge bridge local
78cbbda034dd host host local
709f13f4ce2d none null local
I wanted to reuse the default bridge network, so I added
services:
web:
...
networks:
default:
external:
name: bridge
to the the root of my docker-compose.yml (so not inside one of my
services, but at the root indentation).
I now got the following error:
ERROR: for your-container network-scoped alias is supported only for containers in user defined networks
This led met to this Docker Github
issue, that plainly stated
that I should add the network_mode object to my docker-compose:
version: '3.7'
services:
web:
...
network_mode: bridge
This was tested on Docker version 18.09.8, docker-compose version 1.24.1 and the compose file format 3.7.