Useful Docker Exec Commands for Discourse Sys Admin

Here are some simple but useful docker exec commands for Discourse (assume the container is called app in the standard OOTB configuration):

Running top inside the app container, display on the host:

docker exec -it app top

Add net-tools to the container on Ubuntu using apt outside the container (on the host):

# docker exec -it app apt install net-tools
Reading package lists... Done
Building dependency tree       
Reading state information... Done
net-tools is already the newest version (1.60+git20180626.aebd88e-1).
The following package was automatically installed and is no longer required:
  libllvm7
Use 'apt autoremove' to remove it.
0 upgraded, 0 newly installed, 0 to remove and 6 not upgraded.

Check to see if Rails is running in the Docker container on port 3000:

# docker exec -it app netstat -an | grep :3000
tcp        0      0 127.0.0.1:3000          0.0.0.0:*               LISTEN  

Check to see if a web server in the Discourse app container is listening on port 80:

# docker exec -it app netstat -an | grep :80
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN 

Check the nginx error log inside the Discourse app container from the host:

# docker exec -it app tail -f /var/log/nginx/error.log

Check the current Redix log inside the Discourse app container from the host:

# docker exec -it app tail -f /var/log/redis/current

638:M 08 Jun 2020 09:17:47.070 * 10 changes in 300 seconds. Saving...
638:M 08 Jun 2020 09:17:47.072 * Background saving started by pid 111425
111425:C 08 Jun 2020 09:17:47.199 * DB saved on disk
111425:C 08 Jun 2020 09:17:47.213 * RDB: 0 MB of memory used by copy-on-write
638:M 08 Jun 2020 09:17:47.298 * Background saving terminated with success
638:M 08 Jun 2020 09:22:48.032 * 10 changes in 300 seconds. Saving...
638:M 08 Jun 2020 09:22:48.032 * Background saving started by pid 111785
111785:C 08 Jun 2020 09:22:48.047 * DB saved on disk
111785:C 08 Jun 2020 09:22:48.048 * RDB: 0 MB of memory used by copy-on-write
638:M 08 Jun 2020 09:22:48.133 * Background saving terminated with success

List plugins in the plugin directory in the container:

# 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

Check the overall Docker allocated disk space in the container:

# docker exec -it app df
Filesystem     1K-blocks     Used Available Use% Mounted on
overlay         51043548 26452540  21979460  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 26452540  21979460  55% /shared
tmpfs            1017712        0   1017712   0% /proc/acpi
tmpfs            1017712        0   1017712   0% /proc/scsi
tmpfs            1017712        0   1017712   0% /sys/firmware

Install a plugin with git, clear the cache and restart unicorn from outside the container:

# docker exec -it app git clone <your favorite discourse plugin> /var/www/discourse/plugins
# docker exec -it app rm -rf /var/www/discourse/tmp/cache
# docker exec -it app /usr/bin/sv restart unicorn

ok: run: unicorn: (pid 112786) 0s

Check which version(s) of postgresql is installed in the app container from the host:

# docker exec -it app ls -l /etc/postgresql
total 4
drwxr-xr-x 3 postgres postgres 4096 Jun  7 04:49 10

Does anyone have any more useful docker exec commands to run outside the Discourse container when administering the containerized app??

If so, please share them with everyone.

Thanks.

1 Like