0% found this document useful (0 votes)
4 views

Docker

Docker is a platform for building, running, and shipping applications in isolated environments called containers. It utilizes a client-server architecture and allows developers to package applications with their dependencies into images, which can be stored in registries like Docker Hub. Docker Compose simplifies the management of multi-container applications by allowing users to define services, networks, and volumes in a single YAML file.

Uploaded by

leonelgomez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Docker

Docker is a platform for building, running, and shipping applications in isolated environments called containers. It utilizes a client-server architecture and allows developers to package applications with their dependencies into images, which can be stored in registries like Docker Hub. Docker Compose simplifies the management of multi-container applications by allowing users to define services, networks, and volumes in a single YAML file.

Uploaded by

leonelgomez
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

----------------Docker--------------------------------

A docker is a platform for building, running and shipping apps.


Es un contenedor donde uno puede usar las dependencias que nesecita el app para correrlo en un
ambiente aislado.

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>

Technically a container is just a process like other process.

Containers on a host share the OS of the host.

-------------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-------------------------------

Command to Open VS code .

Here are the instructions for deploying this program:

We have to follow 4 steps for a simple program.


What if you were working with a really complex app, you would end up with a complex release
document that had to be precisely followed.
So that’s docker comes to the rescue, we can write these instructions inside a docker file and
let docker package up our app.

Create a Dockerfile without any extension.


Start from a base image has a bunch of files. we’re going to take those files and add additional files to
it. This is kind of like inheritance in programming.
We can start from a node images.

How do I know these names????


THis images are officialy published on dockerhub.
Dockerhub is a registry for docker images.

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

Command to build a image, the dot . to reference the current directory.


Images is not stored in vs and in fact an image is not a single file.
How store docker an image is very complex, and we don’t worry about it.

To see all images in our computer

Docker Run

Runt the image on any computer running docker.


It doesn’t matter which directory I’m in. Because this image contains all the files for running our app.

We can publish this image to docker hub so anyone can use.

TO pull and run my program


- we type docker pull code

How to push with CLI


- login is required : docker login
- change the name of image if image is not comparable to syntax:
- docker tag imgname: vername username/imgname
-docker push imagename
-----------LInux distributors/ distros

UBUNTU

Shortcut docker run ubuntu


If we have this image locally docker is going to start a container with this image otherwise it’s going to
pull this image behind the scene and then start the container.

Because we didn’t interact with this container, the container stopped.

Ps list of running processes

If we type docker ps -a (all)


Docker run -it(interactive) 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 command on the terminal prints “hello”

“whoami” shows the current user

Echo $0 => shows the location of this shell, the kernel of the program

History => shows the commands we have executed lately

![number] => show the command

Package managers

Apt => advanced package tool (se usa para darle las dependencias que nesecita el programa)

Apt-get

apt update => update the package installed locally

Apt-list => show the list of package installed

Apt install nano

Ctr + L => clear the terminal

-------------------------------------------------------------Linux file system


Windows structure

In linux we have root directory.


In linux everything is a file including devices directories, network, and so on.

----------------------------Navigating the file system-------------------------


Pwd(print working directory) => we can see where we are in the file system.

Ls -1 (item per line )

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../..

Shortcut to get the home directory


Cd ~

---------------------------Manipulating files and directories----------------------


Mkdir test

Change the name => mv (move command) test docker

Touch (command) => to create files

Create mulitple files: touch file1.txt file2.txt …

Move to another directory

Mv [file.name] /[folder directory]

Erase the entire words with Ctr + W

Remove the file


Rm file *

Remove directory
Rm -r [name directory]/

----------------------Editing and viewing files------------

Cat (concatenate , see the content )

More (command to see the content in 15%) only scrown down

Q to exit

Tails

Less
---------------Redirection------------------

The standard input and output


Standard input represents the keyboard
And standard output represents the screen. We can always change the sources of the input and
output, this is called redirection

< redirect the input

A practical guide

----Image like a CD in the past


---container like a pc some enviroment need to execute the cd
Docker -it
Instruct Docker to allocate a sudo terminal connected to the container.
Basically it says that “hey I want to interact with this image just give me a terminal so that I can get
into this and have my terminal to interact with it”

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

----------Docker container prune


-----------------------Mongo DB
El tutorial es sobre que hay 2 containers, uno es de mongo express container y el otro mongo db.

El contenedor de mongoexpress depenede de mongodb contenedor.Entonces tenemos que hacer

conexion entre ellos.

Container talking to container

--exercise

Se instancia el container de mongo

Se instancia el contianer de mongo express


People want to deploy mongoDb and MongoDb might interact with multiple apps.
So here’s a database and there is an app which wants to interact.

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.

Connect Mongo-express with the mongoDB

Dash “/” continue to writing

----------------------------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.

La identation es muy importante


THe problem in the docker world is that the data doesn’t persist that means the container is a
removable item. It’s a detachable item. Anything that you mentioned or have used in that actually
gets away from the container.
That is good thing imagine you are making any sensitive apps specially like a code engine.
You have a change that somebody might throw up a malicious code. You have execute that maybe
that code might entirely corrupt your system. But you don’t worry too much because it’s a docker
container everything just goes away after that.

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

Services is the volumes

Configurar volumes para que persista los datos

Difference docker-compose.ym vs Dockerfile

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.

FROM(specifying the base image)


RUN (executing commands inside the images)
COPY (copying files into a image)
CMD (defining the default command to run when a container is started)

------------Create image----------------------------

Una vez configurado todo del archivo Dockerfile

IIIIII arriba |||||| Run the image


Docker build -t (username de docker)penghe201211944/hey-python-flask .

- d detache mode

Run the container

Docker container run -d -p 3000:3000


penghe201211944/hey-python-flask:lastest

-----------------------------TUTORIAL DE NODE

FROM es la base de la imagen


WORDIR donde se almacenara
COPY . en el directorio actual
RUN command

-------------Docker push

You might also like