Closed pascalandy closed 5 years ago
hi @pascalandy ,
gtop relies on top
ps
command for getting process information. Maybe these resources can help you to figure it out:
Humm the only thing I could see is
docker run --rm -it \
--name gtop \
-v /proc/stat:/proc/stat \
-e LANG=en_US.utf8 -e TERM=xterm-256color \
devmtl/gtop:stable
But it does not work.
/proc
is a virtual file system which contains process information. /proc/stat
has cpu information and already mounted as it is from the host:
Processes are actually listed under /proc
as /proc/ID
:
So if I try to mount /proc
as docker run --rm -it --name gtop -v /proc:/proc:ro gtop
, I am getting following error:
docker: Error response from daemon: oci runtime error: container_linux.go:262: starting container process caused "process_linux.go:339: container init caused \"rootfs_linux.go:57: mounting \\\"/proc\\\" to rootfs \\\"/var/lib/docker/aufs/mnt/0c0d46f3d42d69fb91e850f6a88d13c34436a5d0639022efffe9fd68ac9110a7\\\" at \\\"/proc\\\" caused \\\"\\\\\\\"/var/lib/docker/aufs/mnt/0c0d46f3d42d69fb91e850f6a88d13c34436a5d0639022efffe9fd68ac9110a7/proc\\\\\\\" cannot be mounted because it is located inside \\\\\\\"/proc\\\\\\\"\\\"\"".
To tackle this, other projects such as cAdvisor
and prometheus
mount the host /proc
to a different folder like /proc:/host/proc
(see also https://github.com/prometheus/node_exporter/issues/66).
gtop uses ps
command for process table, if it is running inside a container, it should get process information from /host/proc
instead of /proc
.
also for Network History, you need to add --net="host"
parameter to docker run
We are getting closer :) The network now appears but the processes are still those from the container.
docker run --rm -it \
--name gtop \
--net="host" \
-v /proc:/host/proc:ro \
-e LANG=en_US.utf8 -e TERM=xterm-256color \
devmtl/gtop:stable
You probably want to run as privileged. It might want to be called out here that this is more a docker than a gtop question.
For the process list, you might want to use —pid=host
.
Running in privileged mode is a bad idea. You don’t run top or htop with sudo. Docker provides capability management. If you’re denied permission to access a resource, check if you can add a corresponding capability.
I can help more and even test. But not today.
@jcberthon it worked!
here is Dockerfile
:
FROM node:4
ENV LANG=en_US.utf8 \
TERM=xterm-256color
RUN apt-get update -y && apt-get upgrade -qy && \
npm install gtop -g
ENTRYPOINT ["gtop"]
Building and running the image:
docker build -t gtop .
docker run --rm -it --name gtop --net="host" --pid="host" gtop
More explanation about --pid
: https://docs.docker.com/engine/reference/run/#pid-settings-pid
Thanks @aksakalli Just submit a PR !
I also used FROM node:4-slim
Now, I'm wondering how to package this via zeit-pkg as this image's size is 259MB
REPOSITORY TAG IMAGE ID CREATED SIZE
devmtl/gtop stable c221d2221580 14 minutes ago 259MB
I can't replicate the example from @marcosnils to this project which uses npm install
.
See an example where zeit pkg downsize the image size from 300Mo to 100Mo - https://hackernoon.com/reducing-nodejs-docker-images-size-by-50-using-multi-sage-builds-and-zeit-pkg-360ab8b6c6d2
Cheers!
I have never use npm/node/pkg but from reading the manual from pkg I think you need to define so-called "assets" so that they are "bundled" in the resulting file. See https://www.npmjs.com/package/pkg#assets
In the example from Hackernoon, the "helloworld" is so simple that there is probably no needs for assets, hence it probably works for them.
In the assets, you should put your dependencies I guess. But as I said, I have no clue about npm/node/etc. I know well Docker.
A few more things. In the Dockerfile, you should create a user and define it as the image's user. So that the container is run as a standard user and not root. This is particularly important since you want to give access to all other processes via --pid host
and to your host network devices.
You should also assess if you need an init system for clean shutdown and avoiding zombies. I guess you are not forking any processes and if you do not store any data, then this might not be relevant.
Same for me:
But as I said, I have no clue about npm/node/etc. I know well Docker.
I agree as well and it's a work in progress :)
This is particularly important since you want to give access to all other processes via --pid host and to your host network devices.
Environment
Description
For the docker folks, I'd like to do a PR but I need your help first.
Dockerfile
Try it
Issue
We can see in the screenshot that the processes are those running in the container and not those from the host.
My question is: Which folder(s) should we mount in the container ?
Many cheers!