Creating containers inside a container throws error "docker: not found"

I’m automating the process of creating Docker images from simple ML models.
So far I’m doing it successfully from a flask I’m which call is running in Linux
and has the templates to create the new containers from the models.

Now the next step if to containerize this API, I tried just creating the container and
calling the API but I get this error:

"docker: not found" 

So basically, the docker container has not docker installed, hence I can not create new images from there.

I thought on installing Docker there and find some resources to do it: https://github.com/jpetazzo/dind
But long story short: It is a bad idea.

From another blog, I found this: http://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/

“Do you really want Docker-in-Docker? Or do you just want to be able to run Docker (specifically: build, run, sometimes push containers and images) from your CI system, while this CI system itself is in a container?”

Which it seems to be a solution to my problem here, the blog proposes to use the volume flag to have exposed the socket:

docker run -v /var/run/docker.sock:/var/run/docker.sock ...

which I did:

sudo docker run  -v /var/run/docker.sock:/var/run/docker.sock  -d -p 5100:5100 my_container:latest

But I’m getting the exact same error: “docker: not found” after that.

Source: StackOverflow