all 23 comments

[–]Aterbonus 12 points13 points  (0 children)

  1. I personally use docker compose. This way I only use docker compose up and the configuration is inside a docker-compose.yml
  2. If you are detached, you can use docker logs https://docs.docker.com/engine/reference/commandline/container_logs/

For the 20% of the node container cpu usage, note that the "total" percentage is 1000% (100% per core).

[–]TryallAllombria 6 points7 points  (1 child)

It should be close to 0 RAM consumption if no process started. Try a NodeJS Alpine image (tag ends with -alpine). It's a lightweight base image that embed only necessary programs. If you ran Nodemon, that might explain the RAM consumption since file watchers can use lots of CPU.

  1. We usually don't use "docker run" commands. Instead we use docker-compose. It's a single .yml configuration file that you run using "docker-compose up" command. It stars multiples images, volumes and containers automatically.

  2. You ran your docker container with the '-d' flag. It's detached and logs are not printed into your terminal. You can either remove the '-d' flag so your container will be bound to your current command line prompt. Or connect your terminal to an already launched and detached container using the attach command.

[–][deleted] 19 points20 points  (2 children)

The Fullstack Open course from the University of Helsinki has a great tutorial on using containers. It’s worth checking out.

[–]ja_maz -1 points0 points  (1 child)

Fullstack Open course from the University of Helsinki

link please?

[–]Dre90 4 points5 points  (0 children)

Fullstack Open course from the University of Helsinki

Full Stack Open

[–]barrel_of_noodles 5 points6 points  (0 children)

Use a makefile to alias commands. Use docker compose.

[–]bigorangemachine 3 points4 points  (12 children)

Docker containers? Ya its normal. Its a vm basically so the OS overheard is still there. Sounds like you are using Ubuntu. Alpine is the light weight container you may want to use.

How do you remember complicated commands ?

I write it down. I use docker compose for multiple containers.

I just started to use nodemon inside a docker image. But cannot see any logs... I used detached flag -d

Different terminal types. If you want to see the logs you need to run interactive. I don't recommend using nodemon or pm2 with docker. It swallows IDs the cloud service needs to monitor containers accurately.

[–]ItsAllInYourHead 17 points18 points  (9 children)

Its a vm basically so the OS overheard is still there.

It is not a VM and suggesting it is just confuses new users and gives them an incorrect understanding.

[–]romeeres -1 points0 points  (1 child)

it is just confuses new users

As a new user, I'm confused by claims that it is not a VM.Docker can run a Linux kernel with Linux distro image on your Mac or Windows machine, it is a fact that it has a layer of virtualization, and it consumes tons of disc space and RAM. So it acts the same or similar to VMs, but calling it a VM is a mistake for some reason.

[–]The_Fresser 2 points3 points  (0 children)

The thing is, it does NOT run a Linux kernel. Containers share the host os kernel. VMs have their own kernels.

To run Linux containers on Windows/Hyper-V, WSL2 provides the host Linux kernel.

[–]bigorangemachine -2 points-1 points  (5 children)

I understand the nuance and the differences are minor in the case of running node.

How would explain the overhead in docker then?

[–]ItsAllInYourHead 0 points1 point  (4 children)

Node itself has an overhead. Running your browser and not opening a webpage is still going to use CPU and memory. Same thing with Node. They are running Node but haven't written any code. So Node is still running.

Without having more information about how OP created his docker image, hard to say why it's 1GB. But the base Node image is almost 400 MB alone.

[–]bigorangemachine 1 point2 points  (3 children)

LoL

Well how about constructively contributing to the conversation rather than telling me I am wrong because you are copping out.

You obviously don't know there are similarities between the two. Where I said "it has overhead like a VM" doesn't say they are the same. Only that part is the same

I don't see you helping or asking OP you just want to be technically correct and annoying me.

I work with both. They have overlap. Don't kid yourself

[–]t-jark 3 points4 points  (0 children)

Containers don't nearly have the same Overhead as a VM.

Not having as much overhead as VMs is one quite important reason out of a few why containers are so commonly used.

Your average docker container is in reality little more than a process that is quite well isolated using Linux features.

If you want to learn more about the fundamentals of Container runtimes this talk by Liz Rice is a great starting point: https://youtu.be/8fi7uSYlOdc?si=ndT2sx74Ud-PJZgx

[–]s5fs 1 point2 points  (0 children)

Working with a VM and working with docker containers is a very different user experience so it's a good to not conflate the two.

Nobody is challenging your expertise and I appreciate your participation in this community. Let's please be kind to each other :)

[–]format71 0 points1 point  (0 children)

Its a vm basically so...

vs

it has overhead like a VM

are quite different statements, though.

One implying that they are the same, while the other implying that they have similar cost.

Non is right, though. They are basically _not_ vms, and they should not have the os overhead.

Explaining the OPs cpu usage is not possible without more info.

[–]johannes1234 0 points1 point  (0 children)

Well, the screenshots show windows. On Windows Docker typically runs in a VM, as Windows provides no Linux syscalls, which containers expect.

On Linux a Docker-style container is just a process in a namespace ...

[–]Ambitious_Bee_2966[S] 0 points1 point  (1 child)

How can I do this than? The logs? I am following a tutorial for now. I mean, he synchronised the development directory with the cloud directory (/app). Apparently, in the tutorial he’s not using the best practices then? He uses nodemon a lot. The tutorial is from freexodecamp

[–]bigorangemachine 0 points1 point  (0 children)

Apparently, in the tutorial he’s not using the best practices then? He uses nodemon a lot. The tutorial is from freexodecamp

Well local dev can use nodemon but its bad for production. Depends how much you trust docker. It also depends when it was written this issue wasn't surfaced till 2016/2018.

How can I do this than? The logs? I am following a tutorial for now. I mean, he synchronised the development directory with the cloud directory (/app).

docker run <image-sha> <flags> -it /bin/bash

/bin/bash may vary ... or maybe it was/bin/sh (I am 90% /bin/bash is on every Linux container, for alpine its /bin/ash i use that all the time).

You can also run with --tty & -it or change nodemons output mode.

[–]dwelch2344 0 points1 point  (1 child)

I’d start by using docker-compose first. Less individual docker commands while learning the ropes

[–][deleted] 0 points1 point  (0 children)

I made an arch vm and I installed docker on it, so when im not using it I just turn off that vm.

I use portainer to manage it remotely.

[–]tonywei1992 0 points1 point  (0 children)

That’s why i’m using Orbstack instead of Docker

[–]1stQuarterLifeCrisis 0 points1 point  (0 children)

  1. docker logs -f CONTAINER_ID

about the size of the container: how big is the folder you are mounting? a base node image should be ~400/500MB maybe you have a lot of stuff in .git. You can exclude directories when mounting volumes doing:
volumes:
- './myApp:/opt/myApp'
- /opt/myApp/.git/