Docker es una plataforma Open Source para desarrollar, implementar y ejecutar aplicaciones con contenedores.
Hablar de contenedores no es nuevo, pero la facilidad para implementar aplicaciones fácilmente sí lo es.
Docker utiliza la arquitectura cliente-servidor.
El cliente de Docker habla con el Daemon de Docker quien hace el trabajo de crear, correr y distribuir los contenedores.
Tanto el cliente como el Daemon pueden ejecutarse en el mismo Sistema, o se puede conectar un cliente remoto a un daemon de docker.
Una maquina virtual es un software capaz de cargar en su interior otro sistema operativo.
Un contenedor es la instancia en tiempo de ejecución de una imagen, durante este proceso la imagen es almacenada en memoria.
Es un servicio de registro en la nube que le permite vincular los repositorios de código, almacenar, descargar y buscar imágenes.
Este servicio puede ser utilizado desde la linea de comando o desde la web.
➜ ~ docker search hello-world
==========
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
hello-world Hello World! (an example of minimal Dockeriz… 572 [OK]
kitematic/hello-world-nginx A light-weight nginx container that demonstr… 102
tutum/hello-world Image to test docker deployments. Has Apache… 52 [OK]
dockercloud/hello-world Hello World! 14 [OK]
hypriot/armhf-hello-world Hello World! (an example of minimal Dockeriz… 5
marcells/aspnet-hello-world ASP.NET vNext - Hello World 5 [OK]
armhf/hello-world Hello World! (an example of minimal Dockeriz… 5
crccheck/hello-world Hello World web server in under 2.5 MB 4 [OK]
bonomat/nodejs-hello-world a simple nodejs hello world container 3 [OK]
carinamarina/hello-world-app This is a sample Python web application, run… 1 [OK]
hello-seattle Hello from DockerCon 2016 (Seattle)! 1 [OK]
ppc64le/hello-world Hello World! (an example of minimal Dockeriz… 1
kevindockercompany/hello-world 0
gscrivano/hello-world hello world example system container 0 [OK]
ansibleplaybookbundle/hello-world-apb An APB which deploys a sample Hello World! a… 0 [OK]
ansibleplaybookbundle/hello-world-db-apb An APB which deploys a sample Hello World! a… 0 [OK]
s390x/hello-world Hello World! (an example of minimal Dockeriz… 0
burdz/hello-world-k8s To provide a simple webserver that can have … 0 [OK]
Una imagen es un paquete ejecutable, que tiene todo lo necesario para correr tu aplicación (el código, librerías, variables de entorno, configuraciones, etc).
➜ ~ docker pull hello-world
==========
Using default tag: latest
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:3e1764d0f546ceac4565547df2ac4907fe46f007ea229fd7ef2718514bcec35d
Status: Downloaded newer image for hello-world:latest
Por defecto, docker asume que deseamos descargar la ultima versión de la imagen y le adiciona un tag llamado latest.
➜ ~ docker images
==========
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest e38bc07ac18e 2 months ago 1.85kB
En el campo TAG observamos la versión de la imagen
➜ ~ docker run hello-world
==========
Hello from Docker!
This message shows that your installation appears to be working correctly.
To generate this message, Docker took the following steps:
1. The Docker client contacted the Docker daemon.
2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
(amd64)
3. The Docker daemon created a new container from that image which runs the
executable that produces the output you are currently reading.
4. The Docker daemon streamed that output to the Docker client, which sent it
to your terminal.
To try something more ambitious, you can run an Ubuntu container with:
$ docker run -it ubuntu bash
Share images, automate workflows, and more with a free Docker ID:
https://hub.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
$ docker ps // Lista la info de todos los contenedores encendidos.
$ docker ps -a // Lista la info de todos los contenedores.
$ docker info // Muestra la info del engine de docker.
$ docker stop container_name // Apaga un contenedor.
$ docker rm container_id // Elimina un contenedor.
$ docker exec -it container_id bash // Modo terminal.
➜ ~ docker pull amazonlinux
==========
Using default tag: latest
latest: Pulling from library/amazonlinux
638b75f800bf: Pull complete
Digest: sha256:802212e258f7b67b5754c795f17395937918b29629dd72af615b768f0fcb6cf3
Status: Downloaded newer image for amazonlinux:latest
➜ ~ docker run -it amazonlinux sh
==========
sh-4.2#
sh-4.2# yum install -y vi
sh-4.2# exit
➜ ~ docker ps -a
==========
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cc6e8810eb97 amazonlinux "sh" 5 minutes ago Exited tender_ptolemy
➜ ~ docker commit cc6e8810eb97 amazonlinux-with-vi:latest
==========
sha256:006678859a18aeedfa82b5be3f2eec6506bbe02084c8c10970e94bdc185cf44d
➜ ~ docker images
==========
REPOSITORY TAG IMAGE ID CREATED SIZE
amazonlinux-with-vi latest 006678859a18 33 seconds ago 224MB
FROM amazonlinux
MAINTAINER DevLusaja <janoone52@gmail.com>
RUN yum install -y vi
Es un archivo de texto que en conjunto con el comando docker build nos permite crear una imagen basada en las instrucciones que le indiquemos dentro del mismo.
➜ ~ docker build -t amazonlinux-with-vi-dockerfile .
==========
Sending build context to Docker daemon 4.608kB
Step 1/3 : FROM amazonlinux
---> 585cc50169e6
Step 2/3 : MAINTAINER DevLusaja <janoone52@gmail.com>
---> Running in ece082c29d16
Removing intermediate container ece082c29d16
---> aeeb4ae5c6f9
Step 3/3 : RUN yum install -y vi
---> Running in a5f315cb109f
Loaded plugins: ovl, priorities
Package 2:vim-minimal-7.4.160-2.amzn2.x86_64 already installed and latest version
Nothing to do
Removing intermediate container a5f315cb109f
---> 38f2966cb629
Successfully built 38f2966cb629
Successfully tagged amazonlinux-with-vi-dockerfile:latest
➜ ~ docker images
==========
REPOSITORY TAG IMAGE ID CREATED SIZE
amazonlinux-with-vi-dockerfile latest 38f2966cb629 2 minutes ago 224MB
amazonlinux-with-vi latest 006678859a18 17 minutes ago 224MB