Debian Start Docker
Debian Run Docker As Non Root

Recently, I needed to get cron working inside a Docker container running Debian Slim. Macos catalina bootable installer download. It’s not difficult once you figure it out, but it did take a bit of research and learning to get everything to work.
Step 2 – Install Docker CE on Debian 10. We need to install Docker engine on all the hosts, manager and worker nodes. Install dependency packages on the hosts: sudo apt-get update sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common Add Docker GPG key.
First off, Debian Slim is real slim. There’s no cron
nor is there a syslog
when you want to debug things. Add apt-get install
cron
and rsyslog
in your Dockerfile before you start anything else. With syslog
installed, you can tail /var/log/syslog
while you’re debugging your cron files, which is incredibly helpful.
In my case, I wanted to run a few Python scripts on a schedule. Cron natively uses sh
. I’m sure there’s a way to get it to work that way, but I didn’t want to play around with that. I added my scripts directory in Docker to PATH
in my cronfile and set bash
as my SHELL
. My container runs in Docker Swarm, so it was also important that the output for my script landed in the same STDOUT that eventually ends up in docker.log
. /proc/1/rd/1
is the trick for getting output in the right place.
Debian Start Docker Daemon
First, I created a little shell script — build_projects_env.sh
— for my container to run to get things ready for cron. This script enables Bash’s job control, makes sure environment variables are in a place cron can get to them at, and starts up the cron service itself.
- Docker is a container-based application framework, which wraps a specific application with all its dependencies in a container. Docker containers can easily to ship to the remote location on start there without making entire application setup. This tutorial will help you to install Docker on Debian 10 Buster Linux distribution.
- Docker service will not start on Debian on wsl2 #4872.
- To start a stopped container, use docker start, followed by the container ID or the container’s name. Let’s start the Ubuntu-based container with the ID of d9b100f2f636: docker start d9b100f2f636; The container will start, and you can use docker ps to see its status.
- Debian is a Linux distribution that's composed entirely of free and open-source software.
Next, I created my cron file. The below example is where my cron file ended up, once I got everything working. It sets up PATH
to point to my scripts, changes the shell to bash
, make sure cron can see environment variables, and gets my script ready to run each hour piping its output to STDOUT and errors to STDERR.
Having a valid cron file is just half the battle in getting cron to run successfully in Docker. In your Docker file you’ll need to make sure your script is executable and copy your cron file to the right place. Make sure your new cron file is executable with a little chmod
and chown
and then apply your changes.
By default the cron and syslog service will not start on their own. Make sure you start those two service before you run any of your own commands. I do that in my little shell script, but you can do it elsewhere.
Debian Start Docker Automatically
The above is really all you need to get things going. But… your Docker container is going to default to UTC. That’s fine and all, but when I’m setting up specific schedules in cron, I like to think in local time. The below command is one of many ways to change your time zone. Is it the best? I don’t know. It worked for me.
