你好 @EricGT
是的,我认为许多 Discourse 系统管理员会使用:
./launcher enter <container_name>
……来进入正在运行的容器,并在其中检查状态(或执行任务)。
不过请注意,你可以直接使用 Docker(而且很简单)来完成“你似乎想做的”事情。没有必要使用中间 shell 脚本来获取运行中容器的这些信息:
# docker exec -it app whoami
root
你可能会发现这个关于 docker exec 命令语法的链接很有用。
让我们再试几个例子玩玩:
# docker exec -it app ps aux | grep nginx | wc -l
4
# docker exec -it app ps aux | grep redis | wc -l
2
# docker exec -it app df
Filesystem 1K-blocks Used Available Use% Mounted on
overlay 51043548 26426300 22005700 55% /
tmpfs 65536 0 65536 0% /dev
tmpfs 1017712 0 1017712 0% /sys/fs/cgroup
shm 524288 8 524280 1% /dev/shm
/dev/sda 51043548 26426300 22005700 55% /shared
tmpfs 1017712 0 1017712 0% /proc/acpi
tmpfs 1017712 0 1017712 0% /proc/scsi
tmpfs 1017712 0 1017712 0% /sys/firmware
failed to resize tty, using default size
# docker exec -it app du -sh /shared
403M /shared
# docker exec -it app du -sh /shared/uploads
2.0M /shared/uploads
# docker exec -it app ls -l /var/www/discourse/plugins/
total 36
drwxr-xr-x 1 discourse discourse 4096 Jun 7 04:49 discourse-details
drwxr-xr-x 1 discourse discourse 4096 Jun 7 04:49 discourse-local-dates
drwxr-xr-x 1 discourse discourse 4096 Jun 7 04:49 discourse-narrative-bot
drwxr-xr-x 1 discourse discourse 4096 Jun 7 04:49 discourse-presence
drwxr-xr-x 1 discourse discourse 4096 Jun 7 04:49 discourse-unsupported-browser
drwxr-xr-x 12 discourse root 4096 Jun 7 04:49 docker_manager
drwxr-xr-x 1 discourse discourse 4096 Jun 7 04:49 lazy-yt
drwxr-xr-x 11 discourse root 4096 Jun 7 04:49 neo-revive-discourse
drwxr-xr-x 1 discourse discourse 4096 Jun 7 04:49 poll
root@localhost:/var/discourse# docker exec -it app ls -l /shared
total 112
drwxr-xr-x 3 discourse www-data 4096 May 23 09:57 backups
drwxr-xr-x 10 root root 4096 Jun 7 04:55 letsencrypt
drwxr-xr-x 4 root root 4096 May 23 09:43 log
drwxr-xr-x 2 postgres postgres 4096 May 23 09:43 postgres_backup
drwx------ 19 postgres postgres 4096 Jun 7 04:57 postgres_data
drwxrwxr-x 3 postgres postgres 4096 Jun 7 04:57 postgres_run
drwxr-xr-x 2 redis redis 4096 Jun 8 02:56 redis_data
drwxr-xr-x 2 root root 4096 May 28 04:19 ssl
drwxr-xr-x 4 root root 4096 May 23 09:52 state
drwxrwxrwx 4 discourse www-data 4096 Jun 7 04:57 tmp
drwxr-xr-x 3 discourse www-data 4096 May 23 09:46 uploads
希望这些有趣的例子能给你一些灵感,了解如何使用 docker exec 来“了解运行在容器中的实时站点”,正如你向 @EricGT 询问的那样。
这里还有几个有趣的例子:
# docker exec -it app ls -l /shared/tmp/redis.sock
srwxrwxrwx 1 redis redis 0 Jun 7 04:57 /shared/tmp/redis.sock
这个例子其实不是必需的,因为 Unix socket 就在共享卷中,但你可以理解其中的意思:
#docker exec -it app redis-cli -s /shared/tmp/redis.sock monitor
OK
(已截断,包含大量实时流数据)
最后,当然还有我们系统管理员最喜欢的“老把戏”命令:
root@localhost:~# docker exec -it app ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.0 6660 292 pts/0 Ss+ Jun07 0:00 /bin/bash /sb
root 627 0.0 0.0 2308 60 pts/0 S+ Jun07 0:01 /usr/bin/runs
root 628 0.0 0.0 2156 68 ? Ss Jun07 0:00 runsv cron
root 629 0.0 0.0 2156 64 ? Ss Jun07 0:00 runsv rsyslog
root 630 0.0 0.0 2156 68 ? Ss Jun07 0:00 runsv redis
root 631 0.0 0.0 2156 64 ? Ss Jun07 0:00 runsv postgre
root 632 0.0 0.0 2156 64 ? Ss Jun07 0:00 runsv nginx
root 633 0.0 0.0 2156 64 ? Ss Jun07 0:00 runsv unicorn
discour+ 634 0.0 0.1 15128 2484 ? S Jun07 0:35 /bin/bash con
root 635 0.0 0.1 55176 3956 ? S Jun07 0:00 nginx: master
postgres 636 0.0 1.2 351840 26132 ? S Jun07 0:04 /usr/lib/post
root 637 0.0 0.0 2300 60 ? S Jun07 0:00 svlogd /var/l
redis 638 0.3 0.3 56700 7880 ? Sl Jun07 4:01 /usr/bin/redi
root 639 0.0 0.0 156184 588 ? Sl Jun07 0:00 rsyslogd -n
root 640 0.0 0.0 8436 1216 ? S Jun07 0:00 cron -f
www-data 651 0.0 0.3 56628 6852 ? S Jun07 0:00 nginx: worker
www-data 652 0.0 0.0 55668 1676 ? S Jun07 0:00 nginx: cache
postgres 657 0.0 1.8 352116 36776 ? Ss Jun07 0:01 postgres: 10/
(已截断)
正如你所见或可以想象,docker exec 非常有用,希望这些例子能稍微激发你的灵感,@EricGT。
这里还有几个对 Discourse 有用的 docker exec 命令: