Docker network name has an extra "temp_" as prefix, how to remove it?

I use the following docker-compose.yml to start a container,

    version: "2"

    services:
      nacos1:
        image: nacos:latest
        networks:
          nacos_net:
            ipv4_address: 10.0.2.10
        ports:
          - 8848:8848
        volumes:
          - /root/nacos/application.properties:/app/conf/application.properties

    networks:
      nacos_net:
        ipam:
          driver: default
          config:
            - subnet: "10.0.2.0/24"

I think the network name should be “nacos_net”, but it is temp_nacos_net, what is wrong and how to fix this?

# docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
4e2323469ed0        temp_nacos_net      bridge              local

May I suggest to spend some time with online trainings to build up a basic understanding on Docker and Swarm?
docker self paced training
swarm self paced training

Is there any chance that ‘temp’ is the name of the folder that contains the ‘docker-compose.yml’?

yes, you are right, it is, how to remove it?

As far as I know these is the common behavior of docker-compose; It use the parent folder name as “context/prefix” for all the resources it’s controls.
I’m sure that if you run ‘docker ps -a’, the ‘nacos1’ container is named ‘temp_nacos1’.
In the case of the network, if you really need use another name, You can create it with ‘docker network create’; and then reference it in the ‘docker-compose’ as “external”.

2 Likes

if you don’t want your network name not to prefix with parent folder. as @mgvazquez suggests
create network:

docker network create nacos_net --subnet=10.0.2.0/24

and your docker-compose.yml should be like this

version: "2"

    services:
      nacos1:
        image: nacos:latest
        networks:
          nacos_net:
        ports:
          - 8848:8848
        volumes:
          - /root/nacos/application.properties:/app/conf/application.properties

    networks:
      nacos_net:
        external: true
        name: nacos_net
1 Like