Docker Compose

Docker compose es un orquestador de contenedores para gestionar diferentes microservicios.

Para instalar Docker Compose vamos a la documentación y elegimos linux. En este momento  la  versión es  la 1.21.2  y el comando para instalarlo es :

$ sudo curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 617 0 617 0 0 872 0 –:–:– –:–:– –:–:– 871
100 10.3M 100 10.3M 0 0 376k 0 0:00:28 0:00:28 –:–:– 287k

Damos permisos para ejecutar el commando:

$ sudo chmod +x /usr/local/bin/docker-compose

Verificamos:

$ docker-compose --version

docker-compose version 1.21.2, build a133471

Red en Docker

Mapeo de puertos  en docker  puerto host:puerto docker

$ sudo docker run -d --name nginx2 -p 8080:80 nginx
$sudo docker ps

CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                   NAMES
cb10b610eef0        nginx               "nginx -g 'daemon of…"   51 seconds ago       Up 50 seconds       0.0.0.0:8080->80/tcp    nginx2

Mapea un puerto aleatorio del host

$ sudo docker run -d -P nginx
$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED              STATUS              PORTS                   NAMES
cb10b610eef0        nginx               "nginx -g 'daemon of…"   51 seconds ago       Up 50 seconds       0.0.0.0:8080->80/tcp    nginx2
2783b74d3985        nginx               "nginx -g 'daemon of…"   About a minute ago   Up About a minute   0.0.0.0:32768->80/tcp   infallible_bartik

Contenedores Docker

El repositorio de contenedores para descargar esta en https://hub.docker.com

Cada repositorio tiene diferentes contenedores.Cada contenedor se etiqueta(tag) para poder diferenciarlos.

Para descargar Ubuntu 14.04

$ sudo docker pull ubuntu:trusty
trusty: Pulling from library/ubuntu
324d088ce065: Pull complete
2ab951b6c615: Pull complete
9b01635313e2: Pull complete
04510b914a6c: Pull complete
83ab617df7b4: Pull complete
Digest: sha256:b8855dc848e2622653ab557d1ce2f4c34218a9380cceaa51ced85c5f3c8eb201
Status: Downloaded newer image for ubuntu:trusty

Si no ponemos etiqueta entonces por defecto se descarga el contenedor con etiqueta «latest».
Vamos a ver las imagenes

$ sudo docker images
[sudo] password for jon:
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
ubuntu              trusty              8cef1fa16c77        2 weeks ago         223MB
hello-world         latest              e38bc07ac18e        5 weeks ago         1.85kB
busybox             latest              8ac48589692a        6 weeks ago         1.15MB

Para borrar imagenes

$ sudo docker rmi 8ac48589692a
Error response from daemon: conflict: unable to delete 8ac48589692a (must be forced) - image is being used by stopped container a9ad22be49f3
$

No deja borrarlo porque tiene asociado un contenedor.

Para ver los contenedores que tenemos creados

$ sudo docker ps -a
185d8d93b1cd        ubuntu              "/bin/bash"              2 hours ago         Exited (0) 2 hours ago                        naughty_lichterman
a9ad22be49f3        busybox             "sh"                     21 hours ago        Exited (0) 21 hours ago                       reverent_lichterman
7487aec705bb        hello-world         "/hello"                 21 hours ago        Exited (0) 21 hours ago                       clever_tereshkova

Para borrar contenedores

$ sudo docker rm a9ad22be49f3
a9ad22be49f3
$ sudo docker rmi 8ac48589692a
Untagged: busybox:latest
Untagged: busybox@sha256:58ac43b2cc92c687a32c8be6278e50a063579655fe3090125dcb2af0ff9e1a64
Deleted: sha256:8ac48589692a53a9b8c2d1ceaa6b402665aa7fe667ba51ccc03002300856d8c7
Deleted: sha256:0314be9edf00a925d59f9b88c9d8ccb34447ab677078874d8c14e7a6816e21e1
$
Vamos a crear nuestro primer contenedor interactivo :
$ sudo docker run -it ubuntu

Unable to find image 'ubuntu:latest' locally
latest: Pulling from library/ubuntu
a48c500ed24e: Pull complete
1e1de00ff7e1: Pull complete
0330ca45a200: Pull complete
471db38bcfbf: Pull complete
0b4aba487617: Pull complete
Digest: sha256:c8c275751219dadad8fa56b3ac41ca6cb22219ff117ca98fe82b42f24e1ba64e
Status: Downloaded newer image for ubuntu:latest
root@185d8d93b1cd:/#

Nos cambia el prompt y lo identifica con el ID del contenedor.

$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                    PORTS               NAMES
185d8d93b1cd        ubuntu              "/bin/bash"         2 minutes ago       Up 2 minutes                                  naughty_lichterman

7487aec705bb        hello-world         "/hello"            19 hours ago        Exited (0) 19 hours ago                       clever_tereshkova

Probamos a instalar curl.

root@185d8d93b1cd:/# apt-get update
root@185d8d93b1cd:/# apt-get install curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
ca-certificates krb5-locales libasn1-8-heimdal libcurl4 libgssapi-krb5-2 libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhx509-5-heimdal libk5crypto3
libkeyutils1 libkrb5-26-heimdal libkrb5-3 libkrb5support0 libldap-2.4-2 libldap-common libnghttp2-14 libpsl5 libroken18-heimdal librtmp1 libsasl2-2 libsasl2-modules libsasl2-modules-db
libsqlite3-0 libssl1.1 libwind0-heimdal openssl publicsuffix
Suggested packages:
krb5-doc krb5-user libsasl2-modules-gssapi-mit | libsasl2-modules-gssapi-heimdal libsasl2-modules-ldap libsasl2-modules-otp libsasl2-modules-sql
The following NEW packages will be installed:
ca-certificates curl krb5-locales libasn1-8-heimdal libcurl4 libgssapi-krb5-2 libgssapi3-heimdal libhcrypto4-heimdal libheimbase1-heimdal libheimntlm0-heimdal libhx509-5-heimdal
libk5crypto3 libkeyutils1 libkrb5-26-heimdal libkrb5-3 libkrb5support0 libldap-2.4-2 libldap-common libnghttp2-14 libpsl5 libroken18-heimdal librtmp1 libsasl2-2 libsasl2-modules
libsasl2-modules-db libsqlite3-0 libssl1.1 libwind0-heimdal openssl publicsuffix
0 upgraded, 30 newly installed, 0 to remove and 0 not upgraded.
Need to get 4580 kB of archives.
After this operation, 14.1 MB of additional disk space will be used.

Do you want to continue? [Y/n]

Salimos del contenedor.

root@185d8d93b1cd:/# exit
exit
$

Para parar un contenedor :

$ sudo docker stop 185d8d93b1cd
 
Para volver a entrar en el contenedor.
$ sudo docker start -i 185d8d93b1cds
root@185d8d93b1cd:/#

Para ejecutar contenedores en background.
-d, –detach

$ sudo docker run -d nginx

Unable to find image 'nginx:latest' locally
latest: Pulling from library/nginx
f2aa67a397c4: Pull complete
3c091c23e29d: Pull complete
4a99993b8636: Pull complete
Digest: sha256:0fb320e2a1b1620b4905facb3447e3d84ad36da0b2c8aa8fe3a5a81d1187b884
Status: Downloaded newer image for nginx:latest
962392723bf524cfe0d17ecc6b9f5d3ca72683e500b5406d6292e6e466c93f69
$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS               NAMES
962392723bf5        nginx               "nginx -g 'daemon of…"   2 minutes ago       Up 2 minutes        80/tcp              brave_ramanujan

Creamos un contenedor con un nombre especifico.

$ sudo docker run -it --name contenedor_ubuntu ubuntu
root@29d208c2f162:/#
$ sudo docker ps
29d208c2f162        ubuntu              "bash"                   8 minutes ago       Up 8 minutes                            contenedor_ubuntu

Para poder ejecutar comandos en el contenedor.

$ sudo docker exec -it contenedor_ubuntu date
Fri May 18 14:40:14 UTC 2018

Para aglutinar todos los comandos relacionados con imagenes tenemos el comando «docker image».

$ sudo docker image --help

Usage:  docker image COMMAND

Manage images

Options:

Commands:
  build       Build an image from a Dockerfile
  history     Show the history of an image
  import      Import the contents from a tarball to create a filesystem image
  inspect     Display detailed information on one or more images
  load        Load an image from a tar archive or STDIN
  ls          List images
  prune       Remove unused images
  pull        Pull an image or a repository from a registry
  push        Push an image or a repository to a registry
  rm          Remove one or more images
  save        Save one or more images to a tar archive (streamed to STDOUT by default)
  tag         Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE

Para aglutinar todos los comandos relacionados con contenedores tenemos el comando docker container.

$ sudo docker container --help

Usage:  docker container COMMAND

Manage containers

Options:

Commands:
  attach      Attach local standard input, output, and error streams to a running container
  commit      Create a new image from a container's changes
  cp          Copy files/folders between a container and the local filesystem
  create      Create a new container
  diff        Inspect changes to files or directories on a container's filesystem
  exec        Run a command in a running container
  export      Export a container's filesystem as a tar archive
  inspect     Display detailed information on one or more containers
  kill        Kill one or more running containers
  logs        Fetch the logs of a container
  ls          List containers
  pause       Pause all processes within one or more containers
  port        List port mappings or a specific mapping for the container
  prune       Remove all stopped containers
  rename      Rename a container
  restart     Restart one or more containers
  rm          Remove one or more containers
  run         Run a command in a new container
  start       Start one or more stopped containers
  stats       Display a live stream of container(s) resource usage statistics
  stop        Stop one or more running containers
  top         Display the running processes of a container
  unpause     Unpause all processes within one or more containers
  update      Update configuration of one or more containers
  wait        Block until one or more containers stop, then print their exit codes

Para ver lo que esta mostrando un contenedor en background.

$ sudo docker logs contenedor_ubuntu --tail 10 

Para matar un contenedor en background.

$ sudo docker kill contenedor_ubuntu

Para ver los recursos que esta consumiendo un contendor.

$ sudo docker top contenedor_ubuntu

o tambien podemos ultilizar

$ sudo docker stats contenedor_ubuntu

Para ver las propiedades y características de contenedores e imágenes en formato JSON.

$ sudo docker inspect contenedor_ubuntu

Ejecutar un bash dentro de un contenedor de ubnutu1.

$ docker exec -it ubuntu1 bash

Instalar Docker CE en Ubuntu 16.04

Vamos a instalar la última versión estable de Docker desde los repositorios oficiales.

Empecezamos actualizando el sistema operativo.

$ sudo apt-get update && sudo apt-get upgrade

Descargamos la clave GPG

$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

Añadimos el repositorio de docker

$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

Actualizamos

$ sudo apt-get update

Instalamos la última versión de Docker CE

$ sudo apt-get install docker-ce

Comprobamos la versión instalada

$ sudo docker --version
Docker version 18.03.1-ce, build 9ee9f40

Para comprobar  como esta el daemon de docker:

$ sudo systemctl status docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2018-05-17 10:35:08 UTC; 3h 6min ago
     Docs: https://docs.docker.com
 Main PID: 4395 (dockerd)
   CGroup: /system.slice/docker.service
           ├─4395 /usr/bin/dockerd -H fd://
           └─4419 docker-containerd --config /var/run/docker/containerd/containerd.toml

Para parar el daemon de docker:

$ sudo systemctl stop docker

Para arrancar el daemon  de docker:

$ sudo systemctl start docker

Para ver mas informacion de los contenedores de docker
$ sudo docker info
Containers: 0
 Running: 0
 Paused: 0
 Stopped: 0
Images: 0
Server Version: 18.03.1-ce
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: 773c489c9c1b21a6d78b5c538cd395416ec50f88
runc version: 4fc53a81fb7c994640722ac585fa9ca548971871
init version: 949e6fa
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.4.0-124-generic
Operating System: Ubuntu 16.04.4 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 989MiB

Vamos a crear nuestro primer contenedor

$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
9bb5a5d4561a: Pull complete
Digest: sha256:f5233545e43561214ca4891fd1157e1c3c563316ed8e237750d59bde73361e77
Status: Downloaded newer image for hello-world:latest

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/

Ver las imagenes descargadas

$ sudo docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
hello-world         latest              e38bc07ac18e        5 weeks ago         1.85kB

Para ver todos los contenedores

$ sudo docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
7487aec705bb        hello-world         "/hello"            12 minutes ago      Exited (0) 12 minutes ago                       clever_tereshkova

Para ver los tamanos de los contenedores

$ sudo docker ps -a -s
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES               SIZE
98003142ea08        ubuntu              "bash"              24 seconds ago      Exited (0) 5 seconds ago                        cocky_shaw          5B (virtual 79.6MB)
7487aec705bb        hello-world         "/hello"            29 minutes ago      Exited (0) 29 minutes ago                       clever_tereshkova   0B (virtual 1.85kB)

Para filtrar los contenedores por el nombre del mismo

$ sudo docker ps -a -f name=cocky_shaw
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                      PORTS               NAMES
98003142ea08        ubuntu              "bash"              11 minutes ago      Exited (0) 11 minutes ago                       cocky_shaw

Extensiones imprescindibles para el editor Atom

Extensiones Atom

El editor Atom tiene muchas extensiones para diferentes funcionalidades.Voy a comentaros las que yo utilizo.

1. Browser-Plus
Para poder lanzar el navegador a pantalla partida dentro de Atom y ver como va quedando nuestra página web.

2. Emmet
Atajos para añadir código.

3. Atom Beautify
Para organizar nuestro código.

4. File Icons
Para mostrarnos un tipo de icono diferente para cada tipo de fichero.

Plugins imprescindibles para la plantilla GeneratePress

Generatepress

Los Plugins imprescindibles para la plantilla GeneratePress son :

1. GP premium (Comprar Licencia).
Las funcionalidades extra de la plantilla GeneratePress.

2. Lightweight Social Icons.
Iconos Redes Sociales.

3. Elige Lightweight Grid Columns.
Crear columnas dentro de las secciones mediante shortcodes.

4. Simple CSS.
Poder modificar el CSS de la plantilla.

5. Cookie Law Info.
Validar ley de cookies de la UE.

6. Contact Form 7.
Añdir formulario de contacto.

7. UpdraftPlus.
Copias de seguridad de WordPress.

8. Yoast SEO.
Solución de SEO para WordPress.

9. TinyMCE Avanced.
Editor Visual de WordPress.

10. SiteOrigin Widgets Bundle.
Widgets para añadir funcionalidades a WordPress.