Home > database >  Why docker container acts differently?
Why docker container acts differently?

Time:10-21

As I understood c120809b91b5 == ubuntu

[dev@fedora ~]$ sudo docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED       STATUS          PORTS     NAMES
c120809b91b5   ubuntu    "bash"    11 days ago   Up 39 minutes             ubuntuContainer

[dev@fedora ~]$ docker run -it --add-host=host.docker.internal:host-gateway ubuntu bash
root@c760c5696300:/# cd testfolder
bash: cd: testfolder: No such file or directory

but why they not similar?

[dev@fedora ~]$ docker exec -it c120809b91b5 bash
(base) root@c120809b91b5:/# cd testfolder
(base) root@c120809b91b5:/testfolder# 

What I do wrong?

I need to run c120809b91b5 container with --add-host=host.docker.internal:host-gateway but can't because ubuntu container acts like another with another internal environment.

CodePudding user response:

try adding "detached"

docker run -d -it --add-host=host.docker.internal:host-gateway ubuntu bash

and then look at the result.

I hope it helps. You probably have some exited docker containers by now look at them with:

docker ps -a

CodePudding user response:

What is happening here is that with docker run you are creating a new container from the ubuntu image. So when you run docker run -it --add-host=host.docker.internal:host-gateway ubuntu bash you are just creating a new container from the ubuntu image which is given a new containerId: c760c5696300

If you run docker ps -a you will see that you now have two containers with containerIds c120809b91b5 and c760c5696300

Please read docs https://docs.docker.com/engine/reference/run/

  • Related