DEV Community

Cover image for #013 Docker Containers
Omar
Omar

Posted on

#013 Docker Containers

Introduction

this is part 13 from the journey it's a long journey(360 day) so go please check previous parts , and if you need to walk in the journey with me please make sure to follow because I may post more than once in 1 Day but surely I will post daily at least one 😍.

And I will cover lot of tools as we move on.


Download app_013

app_013

if you follow part 9

cd location/DevOpsJourney/
git pull
cd app_013
Enter fullscreen mode Exit fullscreen mode

replace location with where you clone the DevOpsJourney repo

if your new go to part 9 and do same steps will download old lecture files and new one.


Build image

docker image build -t app_013 .
Enter fullscreen mode Exit fullscreen mode

build


Containers

first I like to mention that there is no need to docker conatiner you can just put container , docker default option is docker container
container-tip

Let's start

let's run our app

run-it

docker run -it app_013
Enter fullscreen mode Exit fullscreen mode

-it for interactive with docker

i am using terminator on linux , he give me ability to split the terminal , in case you have a normal terminal open new tab , and run

docker ps
Enter fullscreen mode Exit fullscreen mode

you can see our container is running with name silly_mclaren
and it's default name gived by docker to us.

again

when we enter a input the program the container will shutdown.

to able to see shutdown containers we need
container_down

docker ps -a
Enter fullscreen mode Exit fullscreen mode

as we see it's status is exited

to automatically delete the container after it ends do
auto_rm

docker run --rm -it app_013
docker ps -a
Enter fullscreen mode Exit fullscreen mode

we can see that he auto remove our container


running in background

to run in background we add -d

back

docker run -d -it app_013
docker ps
Enter fullscreen mode Exit fullscreen mode

we can see it's running but in background with name amazing_wu

logs

to see our app output (in case of -d) docker logs name

docker logs amazing_wu
Enter fullscreen mode Exit fullscreen mode

to interact with the container that is running in background

docker logs -f amazing_wu
Enter fullscreen mode Exit fullscreen mode

we use -f to do this


Run another one

let's run another container in background also

Alt Text

docker run -d -it app_013
Enter fullscreen mode Exit fullscreen mode

to see the resources used by our containers run

docker logs
Enter fullscreen mode Exit fullscreen mode

show

to stop a container

docker stop amazing_wu
Enter fullscreen mode Exit fullscreen mode

more about containers

you can do a lot with containers , example we can give a name , not a random one , this is you challange

docker run --name app_013 -it app_013 
Enter fullscreen mode Exit fullscreen mode

more about containers run

docker container --help
Enter fullscreen mode Exit fullscreen mode

or see the docs!

Top comments (0)