There are much easier ways to run docker commands inside a container:
- using the docker UNIX socket or what people call docker on docker
DonD:
run -it --rm -v /var/run/docker.sock:/var/run/docker.sock -v /usr/bin/docker:/usr/bin/docker ubuntu:20.04
once you run this you can try to run your docker commands it will work just fine but keep in mind!!
this does the same thing as if you run the commands from your host machine
- Run docker in docker or usually called
DinD:
docker run -d --privileged --name docker \
-e DOCKER_TLS_CERTDIR=/certs \
-v docker-certs-ca:/certs/ca \
-v docker-certs-client:/certs/client \
docker:dind
then you can execute dond commands inside that container running:
docker exec -it dond sh
This is a great alternative for you because it's lightweight and easy to setup!
You can find more here.
In case you insist to use the Ubuntu:18.04 and installing docker inside of it, I would first say you haven't specified how you installed docker it should probably work if you followed how to install Docker on a Ubuntu machine, could be some volume mounting issue aswell, you can try to run these commands once the ubuntu container is created or just use a Dockerfile:
apt-get update &&\
apt-get install curl &&\
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add - &&\
add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu focal stable" &&\
apt-cache policy docker-ce &&\
apt-get install -y docker-ce
and then running docker commands must work properly unless you have some network issues.