1

While searching for a docker-compose file I came across this. I saw that the volumes having 2 instructions I'm pretty sure that 2nd one is mapping but I don't know what's the 1st one.

 volumes:
  - /app/node_modules
  - ./server:/app

I

Rick
  • 13
  • 1
  • 3
  • The linked question has some details on this. Remember that a volume like this takes precedence over both the bind mount and the content in the image, and tells Docker the directory is important user data that must not be updated; so the first line is (among other things) an instruction to Docker to ignore all changes to the application's `package.json`. – David Maze Jul 10 '21 at 10:15

1 Answers1

5

From the docker-compose reference on volumes short-syntax the first format you mentioned - /app/node_modules follows the format SOURCE:]TARGET[:MODE], where you are only providing the TARGET (the path in the container).

When the source is omitted, an anonymous volume is created, meaning the Docker volume will be created for you with a random name. Basically, a volume in the Docker filesystem will be created and mounted to your container at the path /app/node_modules. This is useful if you want to later re-mount and share data between containers like in this example in the docs.

You can read more about Docker volumes here: https://docs.docker.com/storage/volumes/

cam
  • 4,409
  • 2
  • 24
  • 34