Dear
I have created a simple docker network but when i am trying to run the container I got an error as below
anyone can advice please …
the error is
**PS C:\Users\Ashraf> docker exec -it container1 bash**
**What’s next:**
**Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug container1**
**Learn more at [docker debug | Docker Docs](docs.docker.com/go/debug-cli/)**
**Error response from daemon: container 9283a295ddb9ec51cefdfc6db0b8a12b3009db25607d438557a76c577ba4fa88 is not running**
the whole code is below
PS C:\Users\Ashraf> docker network create mylab-network
cd98f2160df717c75e86d9299d9b1c4986d83ab3d91ce18db2e52881960851ff
PS C:\Users\Ashraf> docker run -d --name container1 --network mylab-network nicolaka/netshoot
Unable to find image 'nicolaka/netshoot:latest' locally
latest: Pulling from nicolaka/netshoot
4abcf2066143: Pull complete
f72249ed6705: Pull complete
d21093198226: Pull complete
ff793c57efef: Pull complete
b8cdfec6d24e: Pull complete
b6621d484422: Pull complete
452eb7889eb5: Pull complete
4f4fb700ef54: Pull complete
89065cf5c037: Pull complete
a4b421d4901a: Pull complete
d5c3ad7ea15a: Pull complete
ab073295bbd0: Pull complete
737c1bf9f2ef: Pull complete
097ac21093f8: Pull complete
59e353e0ee74: Pull complete
Digest: sha256:a20c2531bf35436ed3766cd6cfe89d352b050ccc4d7005ce6400adf97503da1b
Status: Downloaded newer image for nicolaka/netshoot:latest
9283a295ddb9ec51cefdfc6db0b8a12b3009db25607d438557a76c577ba4fa88
PS C:\Users\Ashraf> docker run -d --name container2 --network mylab-network nicolaka/netshoot
282f920a46214e8f9894b3d25753681d4f769689d019efe907d3fead2f0e905d
PS C:\Users\Ashraf> docker exec -it container1 bash
What's next:
Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug container1
Error response from daemon: container 9283a295ddb9ec51cefdfc6db0b8a12b3009db25607d438557a76c577ba4fa88 is not running
PS C:\Users\Ashraf> docker logs container1
PS C:\Users\Ashraf> docker start container1
container1
PS C:\Users\Ashraf> docker exec -it container1 bash
What's next:
Try Docker Debug for seamless, persistent debugging tools in any container or image → docker debug container1
Learn more at https://docs.docker.com/go/debug-cli/
Error response from daemon: container 9283a295ddb9ec51cefdfc6db0b8a12b3009db25607d438557a76c577ba4fa88 is not running
PS C:\Users\Ashraf> docker-compose up -d
no configuration file provided: not found
PS C:\Users\Ashraf>
Containers are created with a given task to perform, that task is set as their main process, and when it’s done, they stop.
Your container uses the image nicolaka/netshoot
When running docker inspect on that image, I see that the default entrypoint is null, and the default command is zsh
When you run just zsh, that task doesn’t tell the container to do anything, and so, it starts and stops immediately
docker run [flags] nicolaka/netshoot [command]
This will create the container while running the command specified
You can create a container that does nothing but sits there idle without stopping if you use tail -f /dev/null as the command
That command will simply tell the container “Follow the /dev/null file”, and that’s what it’ll do, pretty much nothing, but without stopping.
Then you could do docker exec -it [containername] bash to enter an interactive shell.
Alternatively, you could also do something like this: docker run -it --rm nicolaka/netshoot
This would run the container with the normal zsh command, but your terminal will enter its session, and allow you to specify anything running on zsh in the container.
Afterwards, when you run exit, the zsh process will end and the container will stop and remove itself
I got your point you mean I should create and use the container directly
but what if i am using multiple containers and I wana to switch between them and use commands in this one then switch to the other?
can you help me
The first command runs the container with tail -f /dev/null as its main process - Since that process never ends, it simply stays idle.
Then, the second line creates a shell as a secondary task, and enters it.
You could use bash, but since I saw the default command for that container being zsh, I figured you may prefer to use it instead
Exiting that instance will not end the main process and the container will stay idle for further use
May I ask though, what are you trying to achieve ultimately?
Dear I am a new user and try to make a network of containers to learn about ethical hacking course and I am using it only from less than a week if you have a full basic course of docker in ethical hacking plz advice me