Introducción a Docker



Objetivo “Build, Ship, and Run Any App, Anywhere”.

(UBUNTU 16.04)

   $ sudo apt-get update
   $ sudo apt-get install apt-transport-https ca-certificates
   $ sudo apt-key adv --keyserver hkp:// --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
   $ sudo gedit /etc/apt/sources.list.d/docker.list
   deb ubuntu-xenial main
   $ sudo apt-get update
   $ sudo apt-get purge lxc-docker #purge old repo if exists
   $ apt-cache policy docker-engine #Verify that APT is pulling from the right repository.
   $ sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual # it’s recommended to install the linux-image-extra-* kernel packages. The linux-image-extra-* packages allows you use the aufs storage driver. El comando uname -r devuelve la version del kernel
   $ sudo apt-get install docker-engine
   $ sudo service docker start
   $ sudo docker run hello-world #Verify docker is installed correctly.
Ejemplo: “Hello World”
$ docker run ubuntu /bin/echo 'Hello World'
docker run #runs a container.
ubuntu #image
/bin/echo #command
Images and Containers

An image is a lightweight, stand-alone, executable package that includes everything needed to run a piece of software, including the code, a runtime, libraries, environment variables, and config files.

A container is a runtime instance of an image – what the image becomes in memory when actually executed. It runs completely isolated from the host environment by default, only accessing host files and ports if configured to do so.

Images and Registry

When you specify an image, Docker looks first for the image on your Docker host. If the image does not exist locally, then the image is pulled from the public image registry

Se pueden crear imagenes y subirlas al registro público, serán accesibles para todos.
Se pueden crear registros privados.


A repository potentially holds multiple variants of an image. When you run a container you refer to a tagged image like so:
$ docker run -t -i ubuntu:14.04 /bin/bash

If you don’t specify a variant default to using the ubuntu:latest image

Interactive and Daemonized containers


A grandes rasgos podemos identificar a los contenedores como:
1) Una vez ejecutado, terminan: Ejemplo “Hello World”
2) Una vez ejecuta, no terminan: Ejemplo “Interactive” y “Daemonized”.

Ejemplo: “Interactive container”

$ docker run -t -i ubuntu /bin/bash


-t flag assigns a pseudo-tty or terminal inside the new container.
-i flag allows you to make an interactive connection by grabbing the standard in (STDIN) of the container.
/bin/bash launches a Bash shell inside our container.

Now, you can play around inside this container. When completed, run the exit command or Ctrl-D.

Ejemplo: “Daemonized container”

$ docker run -d ubuntu /bin/sh -c “while true; do echo hello world; sleep 1; done”


-d flag runs the container in the background (to daemonize it).
/bin/sh -c “while true; do echo hello world; sleep 1; done” command to run
1e5535038e285177d5214659a068137486f96ee5c2e85a4ac52dc83f2ebe4147 container ID



Para ejecutar una aplicación, se necesita correr una imagen. Al correr una imagen se define un contenedor

  CONTAINER = docker run IMAGEN [+ commands] 

docker images #See the images you’ve previously used in the user guide
docker pull image_name #Preload images, eg. docker pull centos
docker search image_name #Search images
docker rmi image_name #Remove image from the host

docker ps #List running containers and show information (short version of container id, container name, etc)
docker log container_name #Shows the standard output of a container.
docker stop container_name #Stop running container
docker start container_name #iniciar contenedor
docker rm container_name #eliminar contenedor

docker ps -l #Return the details of the last container started.
docker ps -a #See stopped containers

docker log -f #act like the tail -f

docker exec -i -t container_name /bin/bash #acceder a una terminal de un docker corriendo



Documentación sobre como crear y subir imágenes a un repositorio:

Ultima actualización 10/10/2016

Leave a Reply

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>