Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running gtop in Docker #50

Closed
pascalandy opened this issue Sep 26, 2017 · 15 comments · Fixed by #55
Closed

Running gtop in Docker #50

pascalandy opened this issue Sep 26, 2017 · 15 comments · Fixed by #55
Labels

Comments

@pascalandy
Copy link
Contributor

pascalandy commented Sep 26, 2017

Environment

  • OS: debian
  • Node version: 4.8
  • gtop version: 0.14

Description

For the docker folks, I'd like to do a PR but I need your help first.

Dockerfile

FROM node:4

RUN apt-get update -y && apt-get upgrade -qy && \
    npm install gtop -g

ENTRYPOINT ["gtop"]

Try it

docker run --rm -it \
--name gtop \
-e LANG=en_US.utf8 -e TERM=xterm-256color \
devmtl/gtop:stable

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 ?

screen shot 2017-09-26 at 2 07 29 pm

Many cheers!

@aksakalli
Copy link
Owner

aksakalli commented Sep 26, 2017

hi @pascalandy ,

gtop relies on top ps command for getting process information. Maybe these resources can help you to figure it out:

@pascalandy
Copy link
Contributor Author

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.

@aksakalli
Copy link
Owner

aksakalli commented Sep 26, 2017

/proc is a virtual file system which contains process information. /proc/stat has cpu information and already mounted as it is from the host:

screenshot from 2017-09-26 23-58-14

Processes are actually listed under /proc as /proc/ID:

screenshot from 2017-09-26 23-58-14 another copy

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 prometheus/node_exporter#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.

@aksakalli
Copy link
Owner

also for Network History, you need to add --net="host" parameter to docker run

@pascalandy
Copy link
Contributor Author

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

screen shot 2017-09-26 at 7 26 39 pm

@ianmiell
Copy link

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.

@jcberthon
Copy link

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.

@aksakalli
Copy link
Owner

aksakalli commented Sep 30, 2017

@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

@pascalandy
Copy link
Contributor Author

pascalandy commented Sep 30, 2017

Thanks @aksakalli
Just submit a PR !

I also used FROM node:4-slim

@pascalandy
Copy link
Contributor Author

pascalandy commented Sep 30, 2017

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!

@jcberthon
Copy link

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.

@jcberthon
Copy link

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.

@pascalandy
Copy link
Contributor Author

pascalandy commented Oct 1, 2017

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.

@ianmiell
Copy link

ianmiell commented Oct 1, 2017

https://zwischenzugs.wordpress.com/2015/06/24/the-most-pointless-docker-command-ever/

@cigzigwon
Copy link

It will not work in a Docker Alpine box w/o procps installed first. Just fixed this today in my cloud.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants