Docker
Docker
Container vs Docker
Virtual Machine
Container
----------------------Docker architecture
Docker uses a client server architecture. It has a client component and that talks to a server
component using REST API. The server also called DOCKER ENGINE>
-------------Development workflow------------------
The the app and dockerize it which means we make a small change so that it can be run by docker, we
just add a docker file to it. A docker file is a plain text file that includes instructions that docker to
package up this app into an image.
This image contains everything our app needs to run everything.
A docker file and give it to docker for packaging our app into an image.
Once we have an image, we tell docker to start a container using that images.
So a container is just a process, but it’s a special kind of process because it has its own file system
which is provided by the image.
Our app get loaded inside a container or a process and this is how we run our app locally.
Once we have this image, we can push it to a docker registry like docker hub, is github to git.
It’s a storage for docker images that anyone can use so once our app image is on docker hub then we
can put it on any machines running docker. This machine has the same image we have on our
development machine which contains a specific version of our app with everything it needs.
----------------Docker in action-------------------------------
FROM images and add additional files to it this is kind of like inheritance in programming
These instructions clearly document our deployment process,
We can start from linux images and then install node on top of it. Or we can start from node images.
We start from that image then we need to copy our app . WE use COPY instruction, we’re going to
copy all the files in the current directory use period “.” into the app directory into the image.
Image has a file system we’re going to create directory called app.
Finally we’re going to use CMD to execute a command.
Node app/app.js
Alternatively
WORKDIR
Docker Run
UBUNTU
What we see is called shell. Shell is a program that takes our command and passes them to the
operating system for execution
Root represents the currently logged in user by default, user which has highest privileges.
A pound # sign means user with highest privileges, in other case use dollar sign $
Echo $0 => shows the location of this shell, the kernel of the program
Package managers
Apt => advanced package tool (se usa para darle las dependencias que nesecita el programa)
Apt-get
Ls -l(ele) => list with a long, this list includes more details
Cd (change directory) [name folder] => called relative path
Cd.. => get out of this directory we can go one level up….
Two level cd../..
Remove directory
Rm -r [name directory]/
Q to exit
Tails
Less
---------------Redirection------------------
A practical guide
Which is sandbox enviroment inside your computer, it needs to expose some port so that outside
your computer or your wold can actually connect over through that port that is what exactly the port
opening or the port maping says, your main computer to this closed enviroment.
This 13.8 and this latest version both needs to have a port.
Now this port 5432 can interact with 4000 machine , and this 5432 can interact with 5000 on my
machine
Whenever you start any kind of database which is like postgres Mysql they just don’t work out of the
box. They have to be passed on some enviroment variable. That hey I know I am the authorized guy.
Two version of postgres but with the same port. They are going to get conflict.
We need to pass one more parameter so that this port conflict can be avoided
PORT MAPPING CONCEPT
Images like dvd and container almost like virtual machines in your system.
-p is a port from the host you want to open up so that port can interact with the port of your image.
--------------Docker logs
--exercise
A mongoDb container and the container that express guys have written.THis container is dependent
on this mongoDb so we can make a connection btw them.
The goal is here the app given to you by a developer in the container format and you want to put that
or link that with mongodb container given to you by the mongodb guys.
Container talking to container that is what the devops role is and that is how you work on.
It’s the job of a developer to containerize the app in the best possible manner.
----------------------------DOCKER COMPOSE-______________---------------_________
We realized quickly that this is not the way gonna work through.
We have all these commands writing into the terminal.
We need a proper way in which we can have a file can write all these things into a file and if
something is wrong we can just go there change these things and volla.
This is exactly where docker compose comes up.
There could be five or more container, ten or more, which needs to run or spend off at the same time.
Docker compose is a simple way of creating file and running that.
----------------------
We do not need write network because DOCKER COMPOSE automatically creates a new network
and put all of your containers in that. That is default. All the docker compose shares the same
network.
In the example we really have this data and we want keeping this data.
We need to understand the docker volumen, some time creates an automatic volumen for you.
Specially for the databases
1 docker-compose.yml
The purpose: this file is used for defining and running multicontainer docker apps. It allows you to
define services, networks, and volumes in a declarative manner
2 Dockerfile
The purpose is used to build a docker image. It contains instructions to specify what should be
included in the image, such as the base iamge, dependencies, app code and other configurations.
------------Create image----------------------------
- d detache mode
-----------------------------TUTORIAL DE NODE
-------------Docker push