Docker Compose Volume Question

Could someone help me understand the difference between the volumes below? I got this docker-compose examples from the Node-Red website and I don’t understand why there are 2. I want to be able to preserve the data if I have to move host or I need to recreate the container. If I want to store the data /home/docker/node-red where would I put it and is this the correct syntax?

version: "3.7"

services:
  node-red:
    image: nodered/node-red:latest
    environment:
      - TZ=America/Chicago
    ports:
      - "1880:1880"
    networks:
      - node-red-net
    volumes:
      - node-red-data:/data

volumes:
  node-red-data:

networks:
  node-red-net:

Hi :slight_smile:

There is only 1 volume here “node-red-data”, the other one is a network.

If you want to have data saved to: /home/docker/node-red, you can simply convert your compose file to this:

version: "3.7"

services:
  node-red:
    image: nodered/node-red:latest
    environment:
      - TZ=America/Chicago
    ports:
      - "1880:1880"
    networks:
      - node-red-net
    volumes:
      - /home/docker/node-red:/data

networks:
  node-red-net:

Also if you dont use the network part to anything, you can also remove this part to have docker create its default network (here you just define it especially), then you can cook your compose file down to:

version: "3.7"

services:
  node-red:
    image: nodered/node-red:latest
    environment:
      - TZ=America/Chicago
    ports:
      - "1880:1880"
    volumes:
      - /home/docker/node-red:/data
1 Like

@terpz thank you for the explanation! I had it backwards under volumes. I was thinking that I was supposed to put the path where /data was located.