Today I learned about Docker volumes on CircleCI
- Written on: Th Dec 2020
- Last update: Th Dec 2020
Cannot mount volume in CircleCI
One thing I discovered today is that we cannot mount a volume from a folder in CircleCI. CircleCI gives us the possibility to use Docker commands during our jobs. Knowing that, was I would expect was to mount my app into my container :
docker run -it -v ~/app/apps/app:/app my_docker_image
But when I do that it kept throwing me some npm errors like this one:
@npm ERR! path /app/package.json
npm ERR! code ENOENT
npm ERR! errno -2
npm ERR! syscall open
npm ERR! enoent ENOENT: no such file or directory, open '/app/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent
npm ERR! A complete log of this run can be found in:
npm ERR! /root/.npm/_logs/2020-12-17T13_32_24_766Z-debug.log
Makefile:41: recipe for target 'deploy' failed
make: *** [deploy] Error 254
Well, why does my package.json does not exists in my container but it exists in ~/app/apps/app
?
By looking in the container file system, I was shocked when I saw that in fact there wasn't any package.json files. Nothing except a node_modules folder.
root@7184fb8ef820:/app# ls
node_modules
By searching a bit, I found in the CircleCI documentation an article about mounting volumes.
It's not possible to use Docker volume mounting with the docker executor, but using the machine executor it's possible to mount local directories to your running Docker containers. You can learn more about the machine executor here on our docs page.
So If you ever need to use Docker in your CircleCI job, you may use what they call a machine executor.
In the meantime, I'll just run a npm ci && npm run build
like before. Time saved!