Instalar y usar Dockers en Centos 7
Hace un tiempo os enseñamos lo que era un Docker y como lanzarlos en vuestra nas Synology.
Cada vez que hago un laboratorio con dockers les veo mayor utilidad. Y es muy probable que para esta web y para otras que tengo construidas, migre todo a Dockers. Así que en esas cábalas me encuentro y os muestro como hacer una primera instalación en un servidor Centos 7. En este caso una máquina virtual que tengo en mi laboratorio VMware.
INSTALACION DOCKER CENTOS 7
Empezamos con la instalación, yo lo hago como root que para eso es un laboratorio:
[root@localhost ~]# curl -fsSL https://get.docker.com/ | sh
Para usar docker como otro usuario:
sudo usermod -aG docker your-user
Arrancamos el servicio:
systemctl start docker
Verificamos que arranca correctamente:
[root@localhost ~]# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; enabled; vendor prese t: disabled)
Active: active (running) since mar 2017-04-11 15:54:20 CEST; 2s ago
Docs: https://docs.docker.com
Main PID: 2893 (dockerd)
Memory: 15.3M
CGroup: /system.slice/docker.service
├─2893 /usr/bin/dockerd
└─2896 docker-containerd -l unix:///var/run/docker/libcontainerd/d...
abr 11 15:54:19 localhost.localdomain dockerd[2893]: time="2017-04-11T15:54:1...
abr 11 15:54:19 localhost.localdomain dockerd[2893]: time="2017-04-11T15:54:1...
abr 11 15:54:19 localhost.localdomain dockerd[2893]: time="2017-04-11T15:54:1...
abr 11 15:54:19 localhost.localdomain dockerd[2893]: time="2017-04-11T15:54:1...
abr 11 15:54:19 localhost.localdomain dockerd[2893]: time="2017-04-11T15:54:1...
abr 11 15:54:20 localhost.localdomain dockerd[2893]: time="2017-04-11T15:54:2...
abr 11 15:54:20 localhost.localdomain dockerd[2893]: time="2017-04-11T15:54:2...
abr 11 15:54:20 localhost.localdomain dockerd[2893]: time="2017-04-11T15:54:2...
abr 11 15:54:20 localhost.localdomain dockerd[2893]: time="2017-04-11T15:54:2...
abr 11 15:54:20 localhost.localdomain systemd[1]: Started Docker Application ...
Hint: Some lines were ellipsized, use -l to show in full.
Habilitamos docker para que se ejecute en el arranque:
[root@localhost ~]# systemctl enable docker
Created symlink from /etc/systemd/system/multi-user.target.wants/docker.service to /usr/lib/systemd/system/docker.service.
Pues ya está…¿no ha sido difícil no?
Ahora vamos a jugar un poco con lo que hemos instalado.
PRIMEROS PASOS CON DOCKERS EN CENTOS 7
Ahora los comandos que hay que utilizar pasan por una sentencia parecida a ésta:
docker [option] [command] [arguments]
Para revisar todos los subcomandos de los que disponemos:
[root@localhost ~]# docker
Usage: docker COMMAND
A self-sufficient runtime for containers
Options:
--config string Location of client config files (default "/root/.docker")
-D, --debug Enable debug mode
--help Print usage
-H, --host list Daemon socket(s) to connect to (default [])
-l, --log-level string Set the logging level ("debug"|"info"|"warn"|"error"|"fatal") (default "info")
--tls Use TLS; implied by --tlsverify
--tlscacert string Trust certs signed only by this CA (default "/root/.docker/ca.pem")
--tlscert string Path to TLS certificate file (default "/root/.docker/cert.pem")
--tlskey string Path to TLS key file (default "/root/.docker/key.pem")
--tlsverify Use TLS and verify the remote
-v, --version Print version information and quit
Management Commands:
container Manage containers
image Manage images
network Manage networks
node Manage Swarm nodes
plugin Manage plugins
secret Manage Docker secrets
service Manage services
stack Manage Docker stacks
swarm Manage Swarm
system Manage Docker
volume Manage volumes
Commands:
attach Attach to a running container
build Build an image from a Dockerfile
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
events Get real time events from the server
exec Run a command in a running container
export Export a container's filesystem as a tar archive
history Show the history of an image
images List images
import Import the contents from a tarball to create a filesystem image
info Display system-wide information
inspect Return low-level information on Docker objects
kill Kill one or more running containers
load Load an image from a tar archive or STDIN
login Log in to a Docker registry
logout Log out from a Docker registry
logs Fetch the logs of a container
pause Pause all processes within one or more containers
port List port mappings or a specific mapping for the container
ps List containers
pull Pull an image or a repository from a registry
push Push an image or a repository to a registry
rename Rename a container
restart Restart one or more containers
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save one or more images to a tar archive (streamed to STDOUT by default)
search Search the Docker Hub for images
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
tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
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
version Show the Docker version information
wait Block until one or more containers stop, then print their exit codes
Run 'docker COMMAND --help' for more information on a command.
Ahora vamos a comprobar que somos capaces de descargar imágenes. Prueba tonta:
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
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.
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://cloud.docker.com/
For more examples and ideas, visit:
https://docs.docker.com/engine/userguide/
Si queremos buscar imágenes nuevas, por ejemplo, de “centos”:
[root@localhost ~]# docker search centos
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
centos The official build of CentOS. 3254 [OK]
jdeathe/centos-ssh CentOS-6 6.8 x86_64 / CentOS-7 7.3.1611 x8... 63 [OK]
nimmis/java-centos This is docker images of CentOS 7 with dif... 25 [OK]
consol/centos-xfce-vnc Centos container with "headless" VNC sessi... 24 [OK]
gluster/gluster-centos Official GlusterFS Image [ CentOS-7 + Glu... 18 [OK]
torusware/speedus-centos Always updated official CentOS docker imag... 8 [OK]
egyptianbman/docker-centos-nginx-php A simple and highly configurable docker co... 6 [OK]
nathonfowlie/centos-jre Latest CentOS image with the JRE pre-insta... 5 [OK]
centos/mariadb55-centos7 4 [OK]
centos/redis Redis built for CentOS 2 [OK]
harisekhon/centos-scala Scala + CentOS (OpenJDK tags 2.10-jre7 - 2... 2 [OK]
harisekhon/centos-java Java on CentOS (OpenJDK, tags jre/jdk7-8) 2 [OK]
freenas/centos Simple CentOS Linux interactive container 1 [OK]
blacklabelops/centos CentOS Base Image! Built and Updates Daily! 1 [OK]
darksheer/centos Base Centos Image -- Updated hourly 1 [OK]
sgfinans/docker-centos CentOS with a running sshd and Docker 1 [OK]
timhughes/centos Centos with systemd installed and running 1 [OK]
januswel/centos yum update-ed CentOS image 0 [OK]
grossws/centos CentOS 6 and 7 base images with gosu and l... 0 [OK]
grayzone/centos auto build for centos. 0 [OK]
kz8s/centos Official CentOS plus epel-release 0 [OK]
aguamala/centos CentOS base image 0 [OK]
repositoryjp/centos Docker Image for CentOS. 0 [OK]
vcatechnology/centos A CentOS Image which is updated daily 0 [OK]
dmglab/centos CentOS with some extras - This is for the ... 0 [OK]
Instalamos una oficial como es centos:
[root@localhost ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
93857f76ae30: Pull complete
Digest: sha256:4eda692c08e0a065ae91d74e82fff4af3da307b4341ad61fa61771cc4659af60
Status: Downloaded newer image for centos:latest
Arrancamos la imagen descargada:
[root@localhost ~]# docker run centos
Podemos ver las que tenemos arrancadas de esta forma:
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest a8493f5f50ff 4 days ago 192MB
hello-world latest 48b5124b2768 2 months ago 1.84kB
Si queremos conectarnos al docker como lo haríamos como una máquina virtual lanzamos el siguiente comando. Os pongo un ejemplo tonto, como paso de mi host, al docker:
[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# docker run -it centos
[root@f97e6a803bbf /]# hostname
f97e6a803bbf
Ahora le instalamos algo, un ejemplo con mysql:
[root@f97e6a803bbf /]# yum -y install mysql
Una vez instalado, si queremos guardar los cambios deberemos “sellar” el docker para poder utilizarlo de “plantilla” para otros dockers. Así que salimos de él y guardamos de esta forma:
[root@f97e6a803bbf /]# exit
exit
[root@localhost ~]# docker commit -m "Centos+Mysql" -a "El Blog de Negu" f97e6a803bbf repositorio/centos-mysql
sha256:ba6b5228fc45b102f5b69127085c046de91161448b00e595d8af916859408cf8
Ahora vemos una imagen nueva:
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<strong>repositorio/centos-mysql </strong> latest ba6b5228fc45 About a minute ago 365MB
centos latest a8493f5f50ff 4 days ago 192MB
hello-world latest 48b5124b2768 2 months ago 1.84kB
Otros comandos necesarios para manejaros con Dockers.
Dockers activos:
docker ps
Dockers activos e inactivos:
docker ps -a
Último docker creado:
docker ps -l
Parar docker:
docker stop id-contenedor
Arrancar docker:
docker start id-contenedor
Y por ahora más que suficiente para empezar…os seguiremos enseñando más “cosikas” sobre este interesante mundo. ![🙂]()
La entrada Instalar y usar Dockers en Centos 7 aparece primero en VMware Blog.