Docker Community Forums

Share and learn in the Docker community.

How can I run some cut commands in centos container?

I use docker running a CentOS8 container.

I know the image is minimized, so I can not use some commands in it.
such as: clear, systemctl.

[root@e07da148cc16 /]# clear
bash: clear: command not found

is there any way to install some module, so I can run it? or whether there is other not minimized CentOS image with all commands ?

Before asking this question, I have tried amazonlinux, but it do not have service systemctl type commands.

If you need everything in the container, then you probably need a virtual machine, not a container at least not a Docker container. You can try LXD on Linux with wich you can run containers and virtual machines and you can have systemd even in a container. You could install Systemd inside a Docker container but it is not recommended unless you want to test an installation or configuration process. If you want to do that, try one of the Ansible images created by Jeff Geerling. Those images contain python, ansible and systemd as well.

For centos I found this centos/systemd

And now the reasons I don’t recommend it for general purposes:

1 ) You don’t need systemd in a container if you run only one process inside and you can use supervisor to run multiple processes.
2 ) You can acidentally restart your GUI when you start a container which contains systemd. It is not an issue on a server of course. Most of the examples did not work for me to avoid this situation so I had to spend hours on a solution and I don’t completely understand yet what happens and why.
3 ) You need extra privileges for a container to run systemd in it and mount multiple folders like /dev, /sys/fs/cgroup, /run

Other comands can usually be installed with the package manager (dnf, apt or apk)