21 Days of Docker-Day 3 — Building Container Continue
On day 2, we created our first container, in detached mode
http://100daysofdevops.com/day-2%e2%80%8a-%e2%80%8afirst-docker-container/
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 lsCONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES3afb4a8cfeb7 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 bashroot@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 bashlsbinbootdevetchomeliblib64mediamntoptprocrootrunsbinsrvsystmpusrvar
- 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 bashroot@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.
Up to this point, we understand, how to run the container and how to login to that container, let talk about the real world scenario where a developer is developing its code eg: in HTML and he wants to test this code using docker container. In this case, we need to test two scenario
To read the complete story
http://100daysofdevops.com/21-days-of-docker-day-3%e2%80%8a-%e2%80%8abuilding-container-continue/
Please follow me with my Journey
- Website:http://100daysofdevops.com/
- Twitter:@100daysofdevops OR @lakhera2015
- Facebook:https://www.facebook.com/groups/795382630808645/
- Medium:https://medium.com/@devopslearning
- GitHub:https://github.com/100daysofdevops/21_Days_of_Docker
This time to make learning more interactive, I am adding
- Slack
- Meetup
Please feel free to join this group.
Slack:
Meetup Group
If you are in the bay area, please join this meetup group https://www.meetup.com/100daysofdevops/