Docker command inside a docker container

I run a ubuntu container inside docker by command
docker run - it ubuntu bash
And this c9mmand open a bash terminal
But when i try to execute docker command init it shows docker command not found .
Why it is so ?
How can i run docker command inside a docker container?

The bash container has a minimal subset of standard Linux commands like ls or cp, plus bash.

Docker isn’t one of them.

If you really want, you can install it, but you will also need to attach the container to the docker socket or configure the docker daemon to listen on a TCP port.

It’s possible, but why would you want to do it, if I may?

sir i am using docker in wsl2(ubuntu) and try to creat a docker image inside a docker container to run a web application and i am using docker inside docker to tackle with storage usages problem of my remote device .

Not sure to follow, I haven’t used WSL2, but if you can start a docker container like bash, you can start any container.

Also, you don’t need to create a docker container inside a docker container to create a volume to store data.

This is an example, I hope it’ll help, not that I’m using a Mac, so some commands might slightly different.

Creating a directory for my content

mkdir html

Creating a simple HTML file called hello.html inside the directory I just created

echo '<h1>Hello</h1>' > html/hello.html

Starting a docker container with the nginx:alpine image with several arguments:

  1. in backgroup (-d)
  2. listening on port 80
  3. mounting the dir I created (./html) to the dir ‘/usr/share/nginx/html’ inside the container
  4. removing the container after I stop it
docker run -d -v ./html:/usr/share/nginx/html -p 80:80 --rm nginx:alpine

** now I’m waiting for the container to start…**

sleep 3

Calling the webserver on localhost and asking for the simple HTML page

curl http://localhost/hello.html

demo

Have you tried the Docker for Absolute Beginners course here in KodeKloud?

It’s free, and with interactive labs that should help.

Get it Thanks u sir
Already completed the course
Only trying out the things on my own remote enironment