“Running with unpopulated /etc” – Failing to run systemd based container ?

Recently I experienced, systemd based container fails to run in certain version of distros.

For ex: If I run my container with systemd I get below messages.

#docker run –rm -t -i –privileged -v /sys/fs/cgroup:/sys/fs/cgroup:ro
systemd 219 running in system mode. (+PAM +AUDIT +SELINUX +IMA -APPARMOR +SMACK +SYSVINIT +UTMP +LIBCRYPTSETUP +GCRYPT +GNUTLS +ACL +XZ -LZ4 -SECCOMP +BLKID +ELFUTILS +KMOD +IDN) Detected virtualization docker. Detected architecture x86-64. Running with unpopulated /etc. …. Set hostname to . Initializing machine ID from random generator. Populated /etc with preset unit settings. Unit etc-hosts.mount is bound to inactive unit dev-mapper-X.X.root.device. Stopping, too. Unit etc-hostname.mount is bound to inactive unit dev-mapper-X.X.root.device. Stopping, too…. Unit etc-resolv.conf.mount is bound to inactive unit dev-mapper-X.X.root.device. Stopping, too. Cannot add dependency job for unit display-manager.service, ignoring: Unit display-manager.service failed to load: No such file or directory. Startup finished in 106ms. Failed to create unit file /run/systemd/generator.late/network.service: File exists Failed to create unit file /run/systemd/generator.late/netconsole.service: File exists

The line ‘Running with unpopulated /etc’ looked suspicious to me, after some attempts we were able to conclude that, the things were going wrong in absense of ‘/etc/machine-id’ file which used to be there. If you came across similar to this situation, make an entry in your docker file to create /etc/machine-id as shown below and give a try!

#RUN touch /etc/machine-id

now, build your image and start the container from a new image. Let me know how it goes.