You must have come across the /var/run/docker.sock file, this file is used to communicate with the docker daemon from within a container. To run a docker command inside a container you need to access the docker daemon from within a container. To do this you must have the docker socket of the host. Just follow the below steps:
1. To mount the docker socket from the host system.
$ docker run -v /var/run/docker.sock:/var/run/docker.sock -ti ubuntu bash
2. Install docker in the container.
$ curl -sSL https://get.docker.com/ | sh
3.To check the running container.
$ docker ps
Now that you’re within the container, you can run any command.