LINUX

Cómo instalar Docker en CentOS 8

instalar docker centos 8

CentOS 8 viene con sus propias herramientas, buildah y podman, que son compatibles con las imágenes de docker existentes y funcionan sin depender de un demonio, lo que permite la creación de contenedores como usuarios normales, sin la necesidad de permisos especiales.

Estas herramientas aún tienen algunas limitaciones, por lo que en este tutorial, veremos cómo instalar y ejecutar el Docker CE original en Centos 8 usando el repositorio oficial de Docker.

¿Qué es Docker?

Docker es un proyecto de código abierto que permite la creación y distribución de aplicaciones dentro de contenedores, que son entornos estandarizados que se pueden replicar fácilmente, independientemente del sistema host.

Agregar el repositorio de Docker

Primero, debemos agregar un repositorio externo para obtener el Docker CE. Usaremos el repositorio oficial de Docker CE CentOS.

La utilidad DNF config-manager nos permitió, entre otras cosas, habilitar o deshabilitar fácilmente un repositorio en nuestro CentOS. De forma predeterminada, solo los repositorios appstream y baseos están habilitados en CentOS 8. El siguiente paso es agregar y habilitar también el repositorio docker-ce. Todo lo que necesitamos hacer para lograr esta tarea es ejecutar lo siguiente:

$ sudo dnf config-manager --add-repo=https://download.docker.com/linux/centos/docker-ce.repo
Adding repo from: https://download.docker.com/linux/centos/docker-ce.repo

Podemos verificar que el repositorio ha sido habilitado escribiendo el siguiente comando dnf:

$ sudo dnf repolist -v

....

Repo-id      : docker-ce-stable
Repo-name    : Docker CE Stable - x86_64
Repo-revision: 1567619328
Repo-updated : Wed 04 Sep 2019 05:48:48 PM UTC
Repo-pkgs    : 51
Repo-size    : 1.1 G
Repo-baseurl : https://download.docker.com/linux/centos/7/x86_64/stable
Repo-expire  : 172,800 second(s) (last: Mon 30 Sep 2019 09:28:09 PM UTC)
Repo-filename: /etc/yum.repos.d/docker-ce.repo

Instalación del paquete docker-ce

El repositorio contiene varias versiones del paquete docker-ce, para mostrarlas todas podemos ejecutar:

$ dnf list docker-ce --showduplicates | sort -r
Extra Packages for Enterprise Linux 8 - x86_64  501 kB/s | 2.3 MB     00:04    
docker-ce.x86_64            3:19.03.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:19.03.0-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.9-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.8-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.7-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.6-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.5-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.4-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.3-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.2-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.1-3.el7                     docker-ce-stable
docker-ce.x86_64            3:18.09.0-3.el7                     docker-ce-stable
docker-ce.x86_64            18.06.3.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.2.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.1.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.06.0.ce-3.el7                    docker-ce-stable
docker-ce.x86_64            18.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            18.03.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.12.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.09.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.06.0.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.3.ce-1.el7                    docker-ce-stable
docker-ce.x86_64            17.03.2.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.1.ce-1.el7.centos             docker-ce-stable
docker-ce.x86_64            17.03.0.ce-1.el7.centos             docker-ce-stable

Por el momento, la instalación de containerd.io> 1.2.0-3.el7 está bloqueada, que es una dependencia de docker-ce. Debido a esto, tenemos que solucionar este problema. Sin embargo, existe otro problema. Mientras firewalld, el administrador de firewall del sistema esté habilitado, la resolución de DNS dentro de los contenedores de la ventana acoplable no funciona.
Por el momento, esta es la única forma de instalar docker-ce. Actualizaremos el artículo una vez que esté disponible el paquete centos 8 adecuado.

Ahora instalaremos la ventana acoplable con el siguiente comando:

$ sudo dnf -y  install docker-ce --nobest
Last metadata expiration check: 0:35:54 ago on Sun 20 Oct 2019 05:17:37 PM UTC.
Dependencies resolved.

 Problem: package docker-ce-3:19.03.4-3.el7.x86_64 requires containerd.io >= 1.2.2-3, but none of the providers can be installed
  - cannot install the best candidate for the job
  - package containerd.io-1.2.10-3.2.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.3.el7.x86_64 is excluded
  - package containerd.io-1.2.2-3.el7.x86_64 is excluded
  - package containerd.io-1.2.4-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.5-3.1.el7.x86_64 is excluded
  - package containerd.io-1.2.6-3.3.el7.x86_64 is excluded
================================================================================
 Package           Arch   Version                        Repository        Size
================================================================================
Installing:
 docker-ce         x86_64 3:18.09.1-3.el7                docker-ce-stable  19 M
Installing dependencies:
 container-selinux noarch 2:2.94-1.git1e99f1d.module_el8.0.0+58+91b614e7
                                                         AppStream         43 k
 libcgroup         x86_64 0.41-19.el8                    BaseOS            70 k
 containerd.io     x86_64 1.2.0-3.el7                    docker-ce-stable  22 M
 docker-ce-cli     x86_64 1:19.03.4-3.el7                docker-ce-stable  39 M
Enabling module streams:
 container-tools          rhel8                                                
Skipping packages with broken dependencies:
 docker-ce         x86_64 3:19.03.4-3.el7                docker-ce-stable  24 M

Transaction Summary
================================================================================
Install  5 Packages
Skip     1 Package

Total download size: 80 M
Installed size: 338 M
Downloading Packages:
(1/5): container-selinux-2.94-1.git1e99f1d.modu 314 kB/s |  43 kB     00:00    
(2/5): libcgroup-0.41-19.el8.x86_64.rpm         470 kB/s |  70 kB     00:00    
(3/5): containerd.io-1.2.0-3.el7.x86_64.rpm     3.1 MB/s |  22 MB     00:07    
(4/5): docker-ce-18.09.1-3.el7.x86_64.rpm       2.6 MB/s |  19 MB     00:07    
(5/5): docker-ce-cli-19.03.4-3.el7.x86_64.rpm   2.6 MB/s |  39 MB     00:15    
--------------------------------------------------------------------------------
Total                                           4.5 MB/s |  80 MB     00:17     
warning: /var/cache/dnf/docker-ce-stable-091d8a9c23201250/packages/containerd.io-1.2.0-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Docker CE Stable - x86_64                       1.4 kB/s | 1.6 kB     00:01    
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) "
 Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35
 From       : https://download.docker.com/linux/centos/gpg
Key imported successfully
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                        1/1 
  Installing       : docker-ce-cli-1:19.03.4-3.el7.x86_64                   1/5 
  Running scriptlet: docker-ce-cli-1:19.03.4-3.el7.x86_64                   1/5 
  Installing       : containerd.io-1.2.0-3.el7.x86_64                       2/5 
  Running scriptlet: containerd.io-1.2.0-3.el7.x86_64                       2/5 
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                           3/5 
  Installing       : libcgroup-0.41-19.el8.x86_64                           3/5 
  Running scriptlet: libcgroup-0.41-19.el8.x86_64                           3/5 
  Installing       : container-selinux-2:2.94-1.git1e99f1d.module_el8.0.0   4/5 
  Running scriptlet: container-selinux-2:2.94-1.git1e99f1d.module_el8.0.0   4/5 
  Running scriptlet: docker-ce-3:18.09.1-3.el7.x86_64                       5/5 
  Installing       : docker-ce-3:18.09.1-3.el7.x86_64                       5/5 
  Running scriptlet: docker-ce-3:18.09.1-3.el7.x86_64                       5/5 
  Verifying        : container-selinux-2:2.94-1.git1e99f1d.module_el8.0.0   1/5 
  Verifying        : libcgroup-0.41-19.el8.x86_64                           2/5 
  Verifying        : containerd.io-1.2.0-3.el7.x86_64                       3/5 
  Verifying        : docker-ce-3:18.09.1-3.el7.x86_64                       4/5 
  Verifying        : docker-ce-cli-1:19.03.4-3.el7.x86_64                   5/5 

Installed:
  docker-ce-3:18.09.1-3.el7.x86_64                                              
  container-selinux-2:2.94-1.git1e99f1d.module_el8.0.0+58+91b614e7.noarch       
  libcgroup-0.41-19.el8.x86_64                                                  
  containerd.io-1.2.0-3.el7.x86_64                                              
  docker-ce-cli-1:19.03.4-3.el7.x86_64                                          

Skipped:
  docker-ce-3:19.03.4-3.el7.x86_64                                              

Complete!

Ahora debemos habilitar el servicio Docker:

$ sudo systemctl enable --now docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.

Podemos comprobar si el servicio se está ejecutando como debería:

$ systemctl status  docker
● docker.service - Docker Application Container Engine
   Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor pres>
   Active: active (running) since Sun 2019-10-20 18:00:45 UTC; 2min 12s ago
     Docs: https://docs.docker.com
 Main PID: 2856 (dockerd)
    Tasks: 21
   Memory: 53.2M
   CGroup: /system.slice/docker.service
           ├─2856 /usr/bin/dockerd -H fd://
           └─2873 containerd --config /var/run/docker/containerd/containerd.tom>

A partir de esto, podemos ver que todo está bien.

Agregar usuario al grupo de Docker

Se crea el grupo de la ventana acoplable, pero no se agrega ningún usuario al grupo. Agregue su usuario a este grupo para ejecutar comandos de Docker sin sudo.

$ sudo usermod -aG docker $USER
$ id $USER
uid=1000(vagrant) gid=1000(vagrant) groups=1000(vagrant),988(docker)

Cierre sesión e inicie sesión nuevamente para usar Docker sin sudo. Podemos comprobar la versión de Docker con:

$ newgrp docker

$ docker version
Client: Docker Engine - Community
 Version:           19.03.4
 API version:       1.39 (downgraded from 1.40)
 Go version:        go1.12.10
 Git commit:        9013bf583a
 Built:             Fri Oct 18 15:52:22 2019
 OS/Arch:           linux/amd64
 Experimental:      false

Server: Docker Engine - Community
 Engine:
  Version:          18.09.1
  API version:      1.39 (minimum version 1.12)
  Go version:       go1.10.6
  Git commit:       4c52b90
  Built:            Wed Jan  9 19:06:30 2019
  OS/Arch:          linux/amd64
  Experimental:     false

Pruebe la instalación de la ventana acoplable extrayendo la imagen de prueba

Ahora podemos extraer la imagen del contenedor de la ventana acoplable alpina para probar nuestra ventana acoplable instalada:

$ docker pull alpine
Using default tag: latest
latest: Pulling from library/alpine
9d48c3bd43c5: Pull complete 
Digest: sha256:72c42ed48c3a2db31b7dafe17d275b634664a708d901ec9fd57b1529280f01fb
Status: Downloaded newer image for alpine:latest
docker.io/library/alpine:latest

Enumere las imágenes de contenedor descargadas:

$ docker images
REPOSITORY          TAG                 IMAGE ID            CREATED             SIZE
alpine              latest              961769676411        2 months ago        5.58MB

Verifique que Docker CE esté funcionando correctamente ejecutando el contenedor alpine desde la imagen descargada.

$ docker run -it --rm alpine /bin/sh
/ # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.10/main: temporary error (try again later)
WARNING: Ignoring APKINDEX.00740ba1.tar.gz: No such file or directory
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
ERROR: http://dl-cdn.alpinelinux.org/alpine/v3.10/community: temporary error (try again later)
WARNING: Ignoring APKINDEX.d8b2a6f4.tar.gz: No such file or directory
2 errors; 14 distinct packages available
/ # exit

Vemos aquí que obtenemos errores al intentar actualizar con «actualización de apk».

Como se dijo antes, para que la resolución de DNS funcione dentro de los contenedores de Docker, debemos deshabilitar firewalld (también puede ser necesario reiniciar el sistema):

$ sudo systemctl disable firewalld
Removed /etc/systemd/system/multi-user.target.wants/firewalld.service.
Removed /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.

Después de reiniciar, intentaremos nuevamente la actualización de apk:

$ docker run -it --rm alpine /bin/sh
/ # apk update
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/main/x86_64/APKINDEX.tar.gz
fetch http://dl-cdn.alpinelinux.org/alpine/v3.10/community/x86_64/APKINDEX.tar.gz
v3.10.2-189-g393dc02e8c [http://dl-cdn.alpinelinux.org/alpine/v3.10/main]
v3.10.2-189-g393dc02e8c [http://dl-cdn.alpinelinux.org/alpine/v3.10/community]
OK: 10337 distinct packages available
/ # exit

And now it works. This is not a good solution, but for now, this is the only way. Now you can ssh into docker and start using it.

Conclusión

En este momento no hay un paquete Docker oficial de Centos 8. Por ahora, tenemos que usar esta solución para usar el Docker oficial. En este tutorial, hemos aprendido cómo instalar y usar Docker y las imágenes de Docker con la única solución alternativa conocida en este momento.

Leer también:

Publicaciones relacionadas

Deja una respuesta

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

Botón volver arriba
Cerrar