21 Days of Docker-Day 3 - Building Container Continue

On day 2, we created our first container, in detached mode

But we haven’t logged into the container, now it’s a time to logged into that container. Last time the issue we faced that once we logged out of the container it got shutdown, let see how we can deal with this problem

  • We have this container up and running
$ docker container ls
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
3afb4a8cfeb7        nginx               "nginx -g 'daemon of…"   37 hours ago        Up 3 seconds        80/tcp              mytestserver
  • It’s time to log into this container but this time using docker exec and now I am inside my docker container.
$ docker container exec -it 3afb4a8cfeb7 bash
root@3afb4a8cfeb7:/#
  • What exec will do
exec                       Run a command in a running container
-i, --interactive          Keep STDIN open even if not attached
-t, --tty                  Allocate a pseudo-TTY
  • Let’s dig more into it and see the difference -i and -t makes
  • This time let start with -i flag only
$ docker container exec -i 3afb4a8cfeb7 bash
ls
bin
boot
dev
etc
home
lib
mnt
  • As you can see with -i, I am only getting an interactive session but not the terminal
  • Let’s try out the same command but this time only with -t
$ docker container exec -t 3afb4a8cfeb7 bash
root@3afb4a8cfeb7:/# ls
  • As you can see here, we are only getting terminal here but I am not able to interact with it
  • So this needs to be built as a part of your muscle memory that we need to use -i and -t in tandem when we are trying to login to any container.

8 Replies to “21 Days of Docker-Day 3 - Building Container Continue”

  1. *There are some interesting points in time in this article but I don?t know if I see all of them center to heart. There is some validity but I will take hold opinion until I look into it further. Good article , thanks and we want more! Added to FeedBurner as well

  2. *Nice post. I learn something more challenging on different blogs everyday. It will always be stimulating to read content from other writers and practice a little something from their store. I?d prefer to use some with the content on my blog whether you don?t mind. Natually I?ll give you a link on your web blog. Thanks for sharing.

Leave a Reply

Your email address will not be published.