Reputation: 73
Maybe I didn't understand well Docker but I don't see the point making a Dockerfile for my use. in compose I can specify almost everything I need to set in my dockerfile except two points :
1) I didn't find the equivalent for COPY/ADD into docker-compose.yml so I'm using directory but it's making the image from the host. What is the difference between copy and add ? Is it possible to implement it from the docker-compose file ?
2) I didn't find the equivalent for RUN. I'm using a node script so I need to NPM install like you would do with a RUN in dockerfile. The way I found is to set "npm install && node server.js" in the start command of my package.json file. Is there a better way to do it ? Maybe into the command field ?
I'm not very good with English so don't hesitate to ask for precisions. Thanks in advance for your answers.
Upvotes: 7
Views: 4879
Reputation: 4677
1) Here are the official docs between COPY and ADD:
Although ADD and COPY are functionally similar, generally speaking, COPY is preferred. That’s because it’s more transparent than ADD. COPY only supports the basic copying of local files into the container, while ADD has some features (like local-only tar extraction and remote URL support) that are not immediately obvious. Consequently, the best use for ADD is local tar file auto-extraction into the image, as in ADD rootfs.tar.xz /.
You can't do this in a docker-compose.yml, you'd have to use a Dockerfile if you want to add files to the image.
2) docker-compose.yml has both an entrypoint and command override. Similar to how you'd pass a CMD
at runtime with docker, you can do with a docker-compose run
docker run -itd mystuff/myimage:latest bash -c 'npm install && node server.js'
You can do this with docker-compose
, assuming the service name here is myservice:
docker-compose run myservice bash -c 'npm install && node server.js'
If your use case is only running one container, it's probably hard to see the benefits of docker-compose as a beginner. If you were to add a mongodb an nginx container to your dev stack you'd start to see where docker-compose really picks up and gives you benefits. It works best when used to orchestrate several containers that need to run and communicate with each other.
Upvotes: 14