Docker - Containerizing an App


Containerizing an App:

CODE - DOCKERFILE - BUILD -IMAGE

To get our code into Container we need something called Dockerfile

Dockerfile - List of instructions on how to build an image with an app inside. 


The above Dockerfile contains 4 layers and some metadata

Now build an image

docker image build -t apiembark . 

Now run a container from that image

docker container run -d --name test_app -p 8080:8080 apiembark


Code ->Dockerfile -> Docker Image Build

Build Context - Location of our code (My Dockerfile is located in the build context)

But when you type docker image build whatever is in there is get sent to the daemon and processes part of the build.

Now for us, the client and daemon are on the same host


but it is totally possible to have clients talking to remote Daemons over the network



In that case, our build context can absolutely be a remote gihub repo



docker image build -t apiembark https://github.com/project_url

Multi-Stage Builds

Size matters when its come to images
smaller the definitely better

Advantages of smaller images:

  • Faster builds
  • Faster deployments
  • less money wasted on storage
  • less attack surface for the bad guys to aim at
So running our Apps with minimal OS and minimal supporting packages that is the Gold standard




Working with containers:


docker container ls

To login into the container

docker container run -it [IMAGE_NAME] [WHAT PROCESS TO USE]
docker container run -it alpine sh

docker container exec -it [CONT ID or CONT NAME] [WHAT PROCESS TO USE]
docker container exec -it 60 sh

After login into the container to check what are all the process running
ps -elf

we can directly run some commands on the container 
docker container exec 60 la -l

we can output any files from the container
docker container exec 60 cat newfile 

CTRL P+Q is gracefully way of getting out of the container without terminating its main process




Comments

Popular posts from this blog

Postgresql Hacked ? - FATAL: pg_hba.conf rejects connection for host "127.0.0.1", user "postgres", database "", SSL on

AWS RDS