Feed env
to docker container
In the code we need to use const dataPath = path.join(process.env.DATA_PATH || "./data.txt");
When run docker container, we can feed the DATA_PATH
:
docker build -t my-volume .
docker run --env DATA_PATH=/data/num.txt --mount type=volume,src=incrementor-data,target=/data my-volume
Volume actions
docker volume list
docker volume prune
- type=volume: Specifies that we are mounting a Docker volume. Docker volumes are a mechanism to store and manage data among containers.
- src=incrementor-data: Specifies the source of the mount. Here, it indicates the name of the volume is incrementor-data. If this volume doesn't already exist, Docker will create it.
- target=/data: This is the path inside the container where the volume will be mounted. Applications inside the container can access this path to read/write data from/to the volume.