compose icon indicating copy to clipboard operation
compose copied to clipboard

services.xtlab-apache.networks.0 must be a string

Open vinhthanh2006 opened this issue 4 years ago • 1 comments

Hi guys,

When I deploy stack with docker-compose.yml as below on CentOS 7.

version: "3"

services:
xtlab-apache:
image: "httpd:version2"
networks: - my-network: deploy: replicas: 2 placement: constraints: [node.role == worker] ports: - "8080:80"
- "443:443" volumes:
- dir-site:/home/sites/
xtlab-mysql:
image: "mysql:latest" networks: - my-network: environment: MYSQL_ROOT_PASSWORD: abc123
volumes: - /docker/docker_compose/db:/var/lib/mysql
- /docker/docker_compose/db/my.cnf:/etc/mysql/my.cnf
xtlab-php:
image: "php:version2" networks: - my-network volumes: - dir-site:/home/sites/
networks:
my-network: driver: overlay volumes:
dir-site:
driver_opts: device: /mycode/
o: bind

I received a error message as "services.xtlab-apache.networks.0 must be a string" I'm a new one with docker. Can anyone pls help me this issue? Thank you so much.

vinhthanh2006 avatar Jan 25 '22 10:01 vinhthanh2006

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 31 '22 02:07 stale[bot]

@vinhthanh2006 Did you ever find a solution? I get the same Failure services.CONTAINERNAME.networks.0 must be a string when I try to use a manually created network. I discovered through trying random things that the formattting was causing the problem. Even though the formatting was literally copy-pasted from a guide

The formatting that didn't work

version: '3'
services:
  surfshark:
    image: ilteoood/docker-surfshark:latest
    container_name: surfshark
    networks:
      - surfshark:
        ipv4_address: 10.0.22.80
    cap_add: 
      - NET_ADMIN
    devices:
      - /dev/net/tun
    dns:
      - 9.9.9.9
      - 149.112.112.112

  nginx:
    image: jc21/nginx-proxy-manager:latest
    container_name: nginx
    depends_on: 
      - surfshark
    networks:
      - surfshark:
        ipv4_address: 10.0.22.81
    restart: unless-stopped

  duckdns:
    image: lscr.io/linuxserver/duckdns:latest
    container_name: duckdns
    depends_on:
      - surfshark
    networks:
      - surfshark:
        ipv4_address: 10.0.22.82
    restart: unless-stopped

  tvheadend:
    image: lscr.io/linuxserver/tvheadend:latest
    container_name: tvheadend
    depends_on:
      - surfshark
    networks:
      - surfshark:
        ipv4_address: 10.0.22.83
    devices:
      - /dev/dri:/dev/dri
    restart: unless-stopped

  webgrabplus:
    image: lscr.io/linuxserver/webgrabplus:latest
    container_name: webgrabplus
    depends_on:
      - surfshark
    networks:
      - surfshark:
        ipv4_address: 10.0.22.84
    hostname: webgrabplus
    mac_address: 12:34:56:78:90:0F
    restart: unless-stopped


networks:
  surfshark:
    external: true

However, when I removed the - before the network it worked fine

version: '3'
services:
  surfshark:
    image: ilteoood/docker-surfshark:latest
    container_name: surfshark
    networks:
      surfshark:
        ipv4_address: 10.0.22.80
    cap_add: 
      - NET_ADMIN
    devices:
      - /dev/net/tun
    dns:
      - 9.9.9.9
      - 149.112.112.112

  nginx:
    image: jc21/nginx-proxy-manager:latest
    container_name: nginx
    depends_on: 
      - surfshark
    networks:
      surfshark:
        ipv4_address: 10.0.22.81
    restart: unless-stopped

  duckdns:
    image: lscr.io/linuxserver/duckdns:latest
    container_name: duckdns
    depends_on:
      - surfshark
    networks:
      surfshark:
        ipv4_address: 10.0.22.82
    restart: unless-stopped

  tvheadend:
    image: lscr.io/linuxserver/tvheadend:latest
    container_name: tvheadend
    depends_on:
      - surfshark
    networks:
      surfshark:
        ipv4_address: 10.0.22.83
    devices:
      - /dev/dri:/dev/dri
    restart: unless-stopped

  webgrabplus:
    image: lscr.io/linuxserver/webgrabplus:latest
    container_name: webgrabplus
    depends_on:
      - surfshark
    networks:
      surfshark:
        ipv4_address: 10.0.22.84
    hostname: webgrabplus
    mac_address: 12:34:56:78:90:0F
    restart: unless-stopped


networks:
  surfshark:
    external: true

So for yours a similar problem is probably occurring since, though your formatting makes it hard to tell, it appears you are using the - my-network I assume at the proper indentation. I also noticed that you are specifying your network in the example you gave. If your network is already created you have to make sure to specify it in the networks so the containers can attach to it. If you have already created the network it is easy as just labeling it external: true but if you are wanting to create the network my-network you have to specify the parameters in the compose. You have some lines in there that are not part of the networking configuration to my knowledge.

An example from what I believe your compose should look like would be:

version: "3"

services:
  xtlab-apache:
    image: "httpd:version2"
    networks:
      my-network:
    #deploy:      #I'm not sure what these do so you'll have to ignore the indentations
      #replicas: 2      #I'm not sure what these do so you'll have to ignore the indentations
      #placement:      #I'm not sure what these do so you'll have to ignore the indentations
      #constraints: [node.role == worker]      #I'm not sure what these do so you'll have to ignore the indentations
    ports:
    - "8080:80"
    - "443:443"
    volumes:
    - dir-site:/home/sites/
  xtlab-mysql:
    image: "mysql:latest"
    networks:
      my-network:
    environment:
      MYSQL_ROOT_PASSWORD: abc123
    volumes:
    - /docker/docker_compose/db:/var/lib/mysql
    - /docker/docker_compose/db/my.cnf:/etc/mysql/my.cnf
  xtlab-php:
    image: "php:version2"
    networks:
      my-network
    volumes:
    - dir-site:/home/sites/


networks:
  my-network:
    driver: overlay
    #volumes:      #This seems to be in the wrong place
      #dir-site:      #Not sure what this does or why it's here, definitely doesn't belong in Networking
    driver_opts:
      device: /mycode/
      o: bind

You seem to have a volume: trying to sit in the networking for some reason, that may be an issue as well, but I believe your problem, like mine, was caused by the formatting of the containers' network assignments.

Here's a reference that can help: https://docs.docker.com/compose/compose-file/compose-file-v3/#network-configuration-reference

LostOnTheLine avatar Oct 19 '22 00:10 LostOnTheLine

This issue has been automatically marked as not stale anymore due to the recent activity.

stale[bot] avatar Oct 19 '22 00:10 stale[bot]

syntax for networks is either :

  • a mapping, then entry under networks must be a string key (so the reported error)
some-service:
    networks:
      some-network:  
        aliases:
          - alias1
          - alias3
  • a list, with just networks names:
some-service:
    networks:
      - front-tier
      - back-tier

ndeloof avatar Dec 16 '22 12:12 ndeloof