question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Docker: run commands on host?

See original GitHub issue

I found a version that runs on pi: donaldrich/crontab-ui

But when I add a simple command like: sudo apt-get update, or apt-get update I get errors saying sudo and apt-get don’t exist, so my assumption is it is only running these commands inside the container which is kinda useless I think; is there a way to run these commands on the host?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
LordMikecommented, Feb 6, 2021

Updates:

Curiously. Editing my “root” crontab file seems to work… cron picked it up.

I mounted /var/spool/cron/crontabs/ in my container, wrote the crontab with crontab-ui and then stopped the container (to ensure only host cron runs). It failed, as /etc/crontabs didn’t exist (for logging), so all output was ditched. Created that, and then cron ran my command successfully. I found the env var CRON_PATHS controls this path, so I’ve adjusted that to /var/spool...

In the end, I have:

  • Docker container controls host crontab for root (user crontab-ui runs)
  • Host cron runs the crontab and outputs to a directory mounted in crontab-ui
  • Crontab-ui can see my logs

docker-compose.yml

version: '2.3'

services:
  crontabui:
    image: alseambusher/crontab-ui
    environment:
      CRON_PATH: /var/spool/cron/crontabs
      CRON_DB_PATH: /mnt/systems/crontabui/data
    ports:
      - 192.168.1.10:8811:8000
    volumes:
      - ./supervisord.conf:/etc/supervisord.conf
      # Must be identical in host os
      - /var/spool/cron/crontabs:/var/spool/cron/crontabs
      - /mnt/systems/crontabui/data:/mnt/systems/crontabui/data

supervisord.conf

[supervisord]
nodaemon=true

#[program:crontab]
#command=crond -l 2 -f -c %(ENV_CRON_PATH)s
#stderr_logfile = /var/log/crontab-stderr.log
#stdout_logfile = /var/log/crontab-stdout.log

[program:crontabui]
command=node /crontab-ui/app.js
stderr_logfile = /var/log/crontabui-stderr.log
stdout_logfile = /var/log/crontabui-stdout.log
0reactions
stale[bot]commented, Sep 1, 2022

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to run shell script on host from docker container?
IMO this is the best answer. Running arbitrary commands on the host machine MUST be done through some kind of API (e.g. REST)....
Read more >
docker run - Docker Documentation
docker run : The `docker run` command first `creates` a writeable container layer over the specified image, and then `starts` it using the...
Read more >
How to execute a command directly on the host system ...
The best way that I've found to execute commands on the underlying host with an exposed Docker socket is Ian Miell's most pointless...
Read more >
How To Use docker exec to Run Commands in ... - DigitalOcean
To run a command as a different user inside your container, add the --user flag: docker exec --user guest container-name whoami.
Read more >
How can I run a docker exec command inside a ... - Edureka
If you're running the containers on the same host then you can execute docker commands within the container. This can be done by...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found