Tl;dr: When I try executing the clock_settime(...) linux syscall in an Ubuntu 18.04 container it fails with an EPERM error despite the program running as root. Running the exact same program as root outside of the container on Ubuntu 18.04 succeeds.
The program is as follows:
/* main.c: This program sets the clock forward 1 day. */
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
int main( void )
{
struct timespec stime;
if( clock_gettime( CLOCK_REALTIME, &stime) == -1 ) {
perror( "getclock" );
exit( EXIT_FAILURE );
}
stime.tv_sec += (60*60)*24L; /* Add one day */
stime.tv_nsec = 0;
if( clock_settime( CLOCK_REALTIME, &stime) == -1 ) {
perror( "setclock" );
exit( EXIT_FAILURE );
}
return( EXIT_SUCCESS );
}
(Taken from https://users.pja.edu.pl/~jms/qnx/help/watcom/clibref/qnx/clock_settime.html)
When running outside of the container, the date is successfully updated:
# gcc main.c -o pushtime
# date && ./pushtime && date
Wed Dec 12 09:38:36 PST 2018
Tue Dec 11 09:38:38 PST 2018
When running inside of the container, an EPERM error is raised:
# gcc main.c -o pushtime
# docker run -it -v `pwd`:/workspace ubuntu:bionic /workspace/pushtime
setclock: Operation not permitted
Given that the commands are running as root, I'm confused why there would be an error with permissions and I haven't found anything yet in Docker's documentation that explains why.
Edit: I just realized that an easier demonstration of the error is as follows:
root@host:~# sudo docker run -it ubuntu:bionic /bin/bash
root@container:/# date -s '2018-02-01 21:39'
date: cannot set date: Operation not permitted
Thu Feb 1 21:39:00 UTC 2018