docker-node: docker-compose example does not work
According to the README, it looks like I should be able to just create a docker-compose file with the following contents to get an application running:
version: "2"
services:
node:
image: "node:8"
environment:
- NODE_ENV=production
volumes:
- ./:/usr/src/app
expose:
- "8080"
The note underneath implies that simply performing a docker-compose up
will start a container in which the dependencies will be installed via an npm install
and that the application will be started by a npm start
command. However, docker-compose up
just starts a container, executes the node command in the root directory and instantly stops the container since nothing is being executed. This is normal, since the Dockerfile for the node:8
image only contains CMD[ "node" ]
and no working directory.
If you want to run straight from the image you need to at least add a working_dir: /usr/src/app
and an entrypoint to the docker-compose.yml
. In the entrypoint you’ll need to execute a bash script in which you first perform an npm install
followed by an npm start
.
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 9
- Comments: 16 (4 by maintainers)
There are several possible workflow with Docker Compose and addressing them all would make our README huge!
I had the same issue.The problem in my case was windows account.Recently, I changed my windows password and docker was blocked access to the file.Reapplying shared drive resolve the issue.
The following works:
docker-compose.yml
package.json
This is exactly right. I ran into the same issue but for Docker Desktop for Windows.
This is an issue with Docker/Docker Compose mounting your code directory to the container’s directory. The issue is in
Although the Dockerfile has access to copy your code and build the container; Docker is failing during the mounting process. Some steps to resolve the issue:
I was able to resolve this by giving Docker permissions to the drive and restarting the Docker service.
Commenting out the volumes section. This will prevent the error from occurring but does not allow for synchronizing of the code to your app’s directory. This isn’t ideal but rebuilding with
docker-compose up --build
should copy your code to the container and run assuming your Dockerfile has aI had to add a command like command: “/bin/bash -c ‘cd /project && npm install’” to get it working
This saved me ! It was lacking: