Giter Club home page Giter Club logo

Comments (15)

aksakalli avatar aksakalli commented on May 22, 2024 1

@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

from gtop.

ianmiell avatar ianmiell commented on May 22, 2024 1

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

from gtop.

aksakalli avatar aksakalli commented on May 22, 2024

hi @pascalandy ,

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

from gtop.

pascalandy avatar pascalandy commented on May 22, 2024

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.

from gtop.

aksakalli avatar aksakalli commented on May 22, 2024

/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.

from gtop.

aksakalli avatar aksakalli commented on May 22, 2024

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

from gtop.

pascalandy avatar pascalandy commented on May 22, 2024

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

from gtop.

ianmiell avatar ianmiell commented on May 22, 2024

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.

from gtop.

jcberthon avatar jcberthon commented on May 22, 2024

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.

from gtop.

pascalandy avatar pascalandy commented on May 22, 2024

Thanks @aksakalli
Just submit a PR !

I also used FROM node:4-slim

from gtop.

pascalandy avatar pascalandy commented on May 22, 2024

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!

from gtop.

jcberthon avatar jcberthon commented on May 22, 2024

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.

from gtop.

jcberthon avatar jcberthon commented on May 22, 2024

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.

from gtop.

pascalandy avatar pascalandy commented on May 22, 2024

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.

from gtop.

cigzigwon avatar cigzigwon commented on May 22, 2024

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

from gtop.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.