Comments (10)
Have you tried doing a bind-mount for just that file in the compose yaml? (in addition to other volumes in there)
from node-docker-good-defaults.
Just committed a change to compose file in the master branch along with updated README on this topic. Try this:
If you wanted to add a package while docker-compose was running your app:
docker-compose exec node npm install --save <package name>
- This installs it inside the running container.
- Nodemon will detect the change and restart.
--save
will add it to the package.json for nextdocker-compose build
Feel free to re-open this issue with more questions.
from node-docker-good-defaults.
Awesome, this is it! 👍
from node-docker-good-defaults.
When I run docker-compose exec node npm install --save <package name>
, it didn't update package.json or package-lock.json on host (only the files in the container were updated). I am also bind-mounting these files via docker-compose.
My compose file:
version: "2"
services:
parser:
image: parser
build:
context: "./parser"
dockerfile: "docker/Dockerfile"
volumes:
- "./parser/src/:/opt/src"
- "./parser/package.json:/opt/package.json"
- "./parser/package-lock.json:/opt/package-lock.json"
container_name: parser
working_dir: "/opt"
I had to manually:
docker cp parser:/opt/package-lock.json package-lock.json
docker cp parser:/opt/package.json package.json
To update my package.json and lock file and then do a build so that it picks up the changes.
Is there something wrong with my compose file?
I also ran a docker inspect to check:
...
"Mounts": [
{
"Type": "bind",
"Source": "/src/parser/src",
"Destination": "/opt/src",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/src/parser/package-lock.json",
"Destination": "/opt/package-lock.json",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
},
{
"Type": "bind",
"Source": "/src/parser/package.json",
"Destination": "/opt/package.json",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
}
],
...
from node-docker-good-defaults.
@johnnyli4a4c describe your setup. Are you using Docker Desktop, what Host OS, what docker version, etc.
from node-docker-good-defaults.
I'm running it on CentOS 7 virtual machine.
docker --version
Docker version 17.03.2-ce, build f5ec1e2
docker-compose --version
docker-compose version 1.14.0, build c7bdf9e
from node-docker-good-defaults.
First, you should update your versions and try again. Those are over 1.5 years old. Be sure you're installing via the official docs.docker.com
from node-docker-good-defaults.
Sorry to kick a dead issue, but I have a question regarding package-lock.json
with the new bind-mount workflow.
I was getting crazy weird errors from the lock file produced by running npm i
on my macOS host (I think one of the dependencies in my project was trying to link to a local binary or something wacky). The steps I tried were:
rm package-lock.json
: this caused a file not found error that killeddocker-compose up
, because it couldn't mount a non-existent file.touch package-lock.json
: created a zero-byte file that quelled the errors, but subsequent installs never updated the file (in container or host).- Comment-out mount in
docker-compose.yml
, runnpm i
within the running container,cp
out the resultingpackage-lock.json
, un-comment the mount, restart the container: success!
I realize this was probably an edge case, but I like the idea of having a package tree purely sourced from the container environment, and not any particular developer's host system.
Maybe I'm not searching for the right terms, but I've not found anything in the docs that would provide a good workaround, like conditional mounts or something. Maybe script a docker build
that produces/extracts a package-lock.json
as an artifact?
from node-docker-good-defaults.
I'm not sure I understand. Is this a node problem or docker problem? Are you saying there's something in your package-lock that is host specific? Can you give me a test to replicate the issue?
from node-docker-good-defaults.
Steps to reproduce:
- delete/rename
package-lock.json
- run
docker-compose up
- watch it fail because it can't find
package-lock.json
(duh 🤦♂️)
The whole reason I did the apparently stupid thing above was that, in one of my projects, it seemed npm
was trying to build a package tree that was valid in macOS and not Linux (I think it was caused by an image processing package), which led me to a Docker problem (chicken-and-egg issue where cluster can't boot without a bind-mounted package-lock.json
file, but I needed to boot to generate one).
I'm sure this is an edge case, and most people could roll with the package-lock.json
npm outputs on their host, but I'm trying to keep my own boilerplate project up to date, and just noticed that docker-compose up
fails if package-lock.json
is missing. Once you have one, docker-compose exec node npm install --save <package name>
works as expected, it was just getting that first one to work that I was missing.
I still haven't found a way to make docker-compose
continue gracefully if a bind-mounted file is missing. Lacking that, my current idea is to add a npm run bootstrap
action to my own projects that runs a docker build
and exports the resulting package-lock.json
. That can be used the first time you start a new project, or if you ever want to blow away your dependency tree to get a new one.
Again, this isn't a problem with your project (which I totes ❤️ ), but this issue seemed like it related.
from node-docker-good-defaults.
Related Issues (20)
- Add compose sync example, maybe as default
- Explain role and use of file_env function in docker-entrypoint.sh HOT 1
- Can't install dependencies HOT 2
- How to get app code to see /opt/node_modules HOT 2
- Cannot find node_modules HOT 2
- node-docker-good-defaults_node_1 exited with code 1 HOT 3
- Calling workdir twice HOT 2
- About vscode debugging HOT 3
- Bind mountings not working as expected HOT 2
- nodemon app crashed HOT 3
- Starting inspector on 0.0.0.0:9229 failed: address already in use HOT 3
- Question: Where to put app config files? HOT 1
- Is the recommended version still version 2? HOT 2
- Code as root, but node_modules have node user HOT 3
- Kubernetes support? HOT 1
- Failing test after following the README.md instruction
- Use npm ci instead of npm install? HOT 3
- EACCESS on `docker-compose exec node npm i <package>` HOT 2
- [Feature] Add Good practices for "Remote - Containers - VS Code" HOT 1
- Is there some updates? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-docker-good-defaults.