Como saber se um processo está sendo executado no host ou em um contêiner docker

0

Eu tenho muitos gitlab processos, mas gitlab não está instalado no host:

» ps -ef | grep -c gitlab
61

Esses processos, à primeira vista, parecem processos normais:

» ps -ef | grep gitlab | head
root      1161     1  0 06:24 ?        00:00:06 /usr/local/bin/gitlab-runner run --working-directory /home/gitlab-runner --config /etc/gitlab-runner/config.toml --service gitlab-runner --syslog --user gitlab-runner
root      3379  3164  0 06:24 ?        00:00:00 runsvdir -P /opt/gitlab/service log: ...........................................................................................................................................................................................................................................................................................................................................................................................................
root      3390  3389  0 06:24 ?        00:00:00 svlogd -tt /var/log/gitlab/sshd
root      3813  3164  0 06:24 ?        00:00:00 /bin/bash /opt/gitlab/bin/gitlab-ctl tail
root      3814  3813  0 06:24 ?        00:00:00 /opt/gitlab/embedded/bin/ruby /opt/gitlab/embedded/bin/omnibus-ctl gitlab /opt/gitlab/embedded/service/omnibus-ctl* tail
root      3824  3814  0 06:24 ?        00:00:00 sh -c find /var/log/gitlab -type f -not -path */sasl/* | grep -E -v '(config|lock|@|gzip|tgz|gz)' | xargs tail --follow=name --retry
root      3828  3827  0 06:24 ?        00:00:00 tail --follow=name --retry /var/log/gitlab/gitlab-shell/gitlab-shell.log /var/log/gitlab/redis/state /var/log/gitlab/redis/current /var/log/gitlab/sidekiq/state /var/log/gitlab/sidekiq/current /var/log/gitlab/postgres-exporter/state /var/log/gitlab/postgres-exporter/current /var/log/gitlab/redis-exporter/state /var/log/gitlab/redis-exporter/current /var/log/gitlab/postgresql/state /var/log/gitlab/postgresql/current /var/log/gitlab/unicorn/unicorn_stdout.log /var/log/gitlab/unicorn/state /var/log/gitlab/unicorn/unicorn_stderr.log /var/log/gitlab/unicorn/current /var/log/gitlab/gitlab-rails/gitlab-rails-db-migrate-2018-02-28-08-06-37.log /var/log/gitlab/gitlab-rails/grpc.log /var/log/gitlab/gitlab-rails/githost.log /var/log/gitlab/gitlab-rails/application.log /var/log/gitlab/gitlab-rails/gitlab-rails-db-migrate-2018-02-20-15-14-44.log /var/log/gitlab/gitlab-rails/production_json.log /var/log/gitlab/gitlab-rails/api_json.log /var/log/gitlab/gitlab-rails/production.log /var/log/gitlab/nginx/gitlab_error.log /var/log/gitlab/nginx/error.log /var/log/gitlab/nginx/access.log /var/log/gitlab/nginx/current /var/log/gitlab/nginx/gitlab_access.log /var/log/gitlab/node-exporter/state /var/log/gitlab/node-exporter/current /var/log/gitlab/logrotate/current /var/log/gitlab/sshd/current /var/log/gitlab/prometheus/state /var/log/gitlab/prometheus/current /var/log/gitlab/gitlab-monitor/state /var/log/gitlab/gitlab-monitor/current /var/log/gitlab/gitaly/state /var/log/gitlab/gitaly/current /var/log/gitlab/gitlab-workhorse/state /var/log/gitlab/gitlab-workhorse/current
root      3838  3379  0 06:24 ?        00:00:00 runsv gitlab-monitor
root      3843  3379  0 06:24 ?        00:00:00 runsv gitlab-workhorse
root      3845  3833  0 06:24 ?        00:00:00 svlogd -tt /var/log/gitlab/postgresql

Mas eles são processos docker:

» docker ps 
CONTAINER ID        IMAGE                     COMMAND                  CREATED             STATUS                    PORTS                                                                  NAMES
8d0321cae62a        nginx                     "nginx -g 'daemon ..."   3 days ago          Up 26 minutes             0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp                               nginx
e97521e04a5d        apt-cacher                "/bin/sh -c 'chmod..."   4 days ago          Up 26 minutes             0.0.0.0:3142->3142/tcp                                                 apt-cacher
69608a09b0e7        muccg/devpi:latest        "/docker-entrypoin..."   5 days ago          Up 26 minutes             0.0.0.0:3141->3141/tcp                                                 devpi
83d2b5accc94        registry:2                "/entrypoint.sh /e..."   6 days ago          Up 26 minutes             0.0.0.0:45500->5000/tcp                                                registry
76a82938a1a2        redis                     "docker-entrypoint..."   7 days ago          Up 26 minutes             0.0.0.0:6379->6379/tcp                                                 redis
5d58e1fd47f1        gitlab/gitlab-ee:latest   "/assets/wrapper"        7 days ago          Up 26 minutes (healthy)   0.0.0.0:45022->22/tcp, 0.0.0.0:45080->80/tcp, 0.0.0.0:45443->443/tcp   gitlab

Como posso listar facilmente os processos somente de host com:

  • ps
  • top
por dangonfast 13.03.2018 / 06:53

1 resposta

0

Primeiro, use o seguinte comando para obter o ID do processo principal no contêiner:

$ docker inspect -f '{{.State.Pid}}' <container id>

Depois de obter os IDs do processo, você poderá excluir esses IDs do processo da saída do ps. Um exemplo está abaixo:

$ docker inspect -f '{{.State.Pid}}' portainer
5580

Exclua uma linha com 5580 da saída de ps

$ ps aux | grep -v 5580

Você pode criar facilmente um script para percorrer seus contêineres em execução.

    
por 30.03.2018 / 00:02