2

Basing on this Node-RED tutorial, I'm trying to mount an external volume with the Node-RED files outside the docker machine. I'm using the following docker-compose file:

version: "3.7"

services:
  node-red:
    image: nodered/node-red:latest
    environment:
      - TZ=Europe/Amsterdam
    ports:
      - "2000:1880"
    networks:
      - node-red-net
    volumes:
      - node-red-data:/home/user/node-red1
    
volumes:
  node-red-data:
    
networks:
  node-red-net:

However, even though this file works fine when I run docker-compose up, the volume exists only inside the docker machine. I've tried adding the line external: true in volumes but I get the following error:

ERROR: In file './docker-compose.yml', volume 'external' must be a mapping not a boolean. 

What am I missing? How do I mount an external volume using docker-compose files?

Jonas V
  • 668
  • 2
  • 5
  • 20
raylight
  • 447
  • 4
  • 17
  • Are you actually using Docker Machine (or Docker Toolbox)? Where do you want the volume to be? – David Maze Dec 02 '20 at 18:05
  • @DavidMaze I'm using the command line docker-compose... I've added the official docker repository on Ubuntu and installed it with `sudo apt install docker-compose`. The application runs fine when I run `docker-compose`, the only problem is that the volume is not mounted outside docker... Only inside it... I'd like the volume to be on a path that I have on Ubuntu. – raylight Dec 02 '20 at 18:10
  • 1
    You might look at the [Compose `volumes:` syntax for bind mounts](https://docs.docker.com/compose/compose-file/#short-syntax-3) in the Compose file reference. ("External" volumes are named volumes, still not directly accessible from the host, that happen to be created outside of this particular Compose file.) – David Maze Dec 02 '20 at 19:44

1 Answers1

1

I ended up finding a related question with this answer. There are multiple answers that didn't work for me there (also there's no accepted answer). The syntax that worked was:

  node-red-data:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: /path/external/folder

So the final dockerfile that works after running docker-compose up is:

version: "3.7"

services:
  node-red:
    image: nodered/node-red:latest
    environment:
      - TZ=Europe/Amsterdam
    ports:
      - "2000:1880"
    networks:
      - node-red-net
    volumes:
      - node-red-data:/data
    container_name: node-red

volumes:
  node-red-data:
    driver: local
    driver_opts:
      o: bind
      type: none
      device: "/home/user/node-red1"
networks:
  node-red-net:

Update

If we don't mind having a random name for the volume, the following solution also works fine:

version: "3.7"

services:
  node-red:
    image: nodered/node-red:latest
    environment:
      - TZ=Europe/Amsterdam
    ports:
      - "2000:1880"
    volumes:
      - /home/user/node-red1:/data
    container_name: node-red
raylight
  • 447
  • 4
  • 17