User Tools

Site Tools


apuntes:docker

This is an old revision of the document!


Docker

¿Qué es Docker?

Figure 1: Máquina virtual vs Contenedor

Instalación

Docker

santi@zenbook:$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
5b0f327be733: Pull complete 
Digest: sha256:1f19634d26995c320618d94e6f29c09c6589d5df3c063287a00e6de8. . .
Status: Downloaded newer image for hello-world:latest
 
Hello from Docker!
This message shows that your installation appears to be working correctly.
. . .
santi@zenbook:$ docker --version
Docker version 17.05.0-ce, build 89658be

Trabajar con Docker

Lanzar un contenedor

santi@zenbook:$ docker run -it debian bash
Unable to find image 'debian:latest' locally
latest: Pulling from library/debian
219d2e45b4af: Pull complete 
Digest: sha256:126052225b62db18c32f03a4462a92fad2ef243c6509371edb82. . .
Status: Downloaded newer image for debian:latest
root@94565ea1af31:/# 
santi@zenbook:$ docker run -it -v /ruta/completa/host:/ruta/completa/contenedor debian bash
santi@zenbook:$ docker run -d -v /var/www/unsitioweb:/var/www debian

Listar los contenedores en ejecución

santi@zenbook:$ docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
a859e3fdc573        debian              "bash"              10 seconds ago      Up 7 seconds                            laughing_goldstine

Listar todos los contenedores

santi@zenbook:$ docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
5248cf319258        debian              "bash"              7 seconds ago       Exited (0) 2 seconds ago                        silly_wiles
78d990ba4591        hello-world         "/hello"            17 seconds ago      Exited (0) 14 seconds ago                       vibrant_mccarthy

Listar las imágenes locales

santi@zenbook:$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
debian              latest              72ef1cf971d1        6 days ago          100MB
hello-world         latest              05a3bd381fc2        7 days ago          1.84kB

Eliminar un contenedor

santi@zenbook:$ docker rm 78d990ba4591
78d990ba4591

Eliminar una imagen

santi@zenbook:$ docker rmi 05a3bd381fc2
Untagged: hello-world:latest
Untagged: hello-world@sha256:1f19634d26995c320618d94e6f29c. . .
Deleted: sha256:05a3bd381fc2470695a35f230afefd7bf978b56625. . .
Deleted: sha256:3a36971a9f14df69f90891bf24dc2b9ed9c2d20959. . .

Lanzar un contenedor con Apache

santi@zenbook:$ docker run -dit --name miapache -p 5555:80 -v "$PWD":/usr/local/apache2/htdocs httpd:2.4
Unable to find image 'httpd:2.4' locally
2.4: Pulling from library/httpd
aa18ad1a0d33: Pull complete 
2b28e4afdec2: Pull complete 
802b6cd5ed3b: Pull complete 
6f2336b7c318: Pull complete 
d7c441746c9e: Pull complete 
ba7f19f905f9: Pull complete 
5c7522be7faf: Pull complete 
Digest: sha256:a46bd62f5286321ed19875778246f3afe97df5f9e91f0dd369a6ecfa529dbe81
Status: Downloaded newer image for httpd:2.4
444c11d75d0a1e424c5c24668e62357af74de8b801e75d37c1e014e0423c9a2c
santi@zenbook:$ docker ps
CONTAINER ID        IMAGE               COMMAND              CREATED             STATUS              PORTS                  NAMES
444c11d75d0a        httpd:2.4           "httpd-foreground"   21 seconds ago      Up 19 seconds       0.0.0.0:5555->80/tcp   miapache
santi@zenbook:$ docker stop miapache
miapache
santi@zenbook:$ docker start miapache
miapache
santi@zenbook:$
santi@zenbook:$
apuntes/docker.1505870264.txt.gz · Last modified: 2019/01/04 13:02 (external edit)