Some points come into my mind that are strange here:
Install something should be in your Dockerfile used for creating your own image based on (in this case) wodby/node:12-dev-0.84.0 instead being used in your docker-compose.yml. Afterwards you can use your newly created image in your docker-compose.yml.
I have checked with docker run --rm -it wodby/node:12-dev-0.84.0 bash - this image uses apk instead of apt-get to install additional packages. If I remember correctly the syntax is (sudo) apk add <packagename>. Keep in mind that the package-names might be different to the ones you are used to use with apt-get.
Why do you try to install node into an image already containing node
Why do you try to install node into an image already containing node
In fact, if I have a node image, then why should I install a node. I do not install PHP when I have a PHP image.
Therefore, in the themes I wrote only the following commands: command: sh -c 'cd /var/www/html/web/themes/custom/bootstrap_sass_bcnews && npm install --global gulp-cli && npm install && gulp'
But then I get errors:
perceval@Asus:~/Desktop/bcnews_project$ docker-compose logs node
Attaching to bcnews_node
bcnews_node | npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
bcnews_node | npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
bcnews_node | /home/node/.npm-global/bin/gulp -> /home/node/.npm-global/lib/node_modules/gulp-cli/bin/gulp.js
bcnews_node | + gulp-cli@2.3.0
bcnews_node | added 252 packages from 165 contributors in 23.752s
bcnews_node | npm WARN saveError ENOENT: no such file or directory, open '/var/www/html/web/themes/custom/bootstrap_sass_bcnews/package.json'
bcnews_node | npm WARN saveError EACCES: permission denied, open '/var/www/html/web/themes/custom/bootstrap_sass_bcnews/package-lock.json.3294245740'
bcnews_node | npm WARN enoent ENOENT: no such file or directory, open '/var/www/html/web/themes/custom/bootstrap_sass_bcnews/package.json'
bcnews_node | npm WARN bootstrap_sass_bcnews No description
bcnews_node | npm WARN bootstrap_sass_bcnews No repository field.
bcnews_node | npm WARN bootstrap_sass_bcnews No README data
bcnews_node | npm WARN bootstrap_sass_bcnews No license field.
bcnews_node |
bcnews_node | up to date in 0.5s
bcnews_node | found 0 vulnerabilities
bcnews_node |
bcnews_node | [18:19:30] Local gulp not found in /var/www/html/web/themes/custom/bootstrap_sass_bcnews
bcnews_node | [18:19:30] Try running: npm install gulp
So, you can use Compose’s command to change the way you start the container, not to install something every time the container is started. In other words, like already noted:
As for:
Your Compose command finishes after installing, so the container indeed stops, as expected.
Node.js by itself is just an interpreter for a programming language; it does not “run” anything unless being told so. The things you specified in command do not start anything after the installation is complete. Common usage would be to start a web server using some server-side JavaScript code. That is then typically configured in Dockerfile using CMD, or overridden in docker-compose.yml using command.
As wodby/node provides no documentation I have no idea what that does. (It could be mining crypto currency for all we know.) But for the official node image, one could use command: "node my-server.js" or command: "npm start" in Compose, or use CMD ["node", "my-server.js"] or CMD ["npm", "start"] in a Dockerfile. That all depends on the application you’re trying to run though. Nice read: Building Efficient Dockerfiles - Node.js.
(Aside, please don’t post the same thing in multiple places. Success!)
Node.js image uses apk instead of apt-get to install additional packages.
This image already containing node.js. I don’t need to write a node.js installation command in command: line.
Here’s how the node service configuration should look like: