I want to run a container which:
- Has a non-root user running it by default (USER Dockerfile instruction)
- Runs a system service (CMD Dockerfile instruction) as crontab
The simplest thing one can think to is to execute the following Dockerfile:
FROM openjdk:8
RUN apt-get update && apt-get -y install nano
RUN apt-get update && apt-get -y install cron
RUN useradd -u 8877 dockeras
RUN mkdir /home/dockeras
RUN chown -R dockeras /home/dockeras && chmod -R u+rwx /home/dockeras
USER dockeras
CMD ["cron", "-f"]
Obviously, the CMD instruction will return an error because the cron service requires to be run by root. How to solve this?
You could implement it like this: Dockerfile and startup.sh
Dockerfile
startup.sh