sudo apt update
sudo apt -y dist-upgrade
sudo apt -y install curl
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh ./get-docker.sh
sudo usermod -a -G docker $USER
sudo su - $USER
docker run hello-world
docker COUSIÑA COMANDO
Cousiñas: contedores, images, volumes, network.
Exemplos:
docker {image, volume, network} ls
docker {image, volume, network} rm ID
docker ps -a
docker rm ID
docker build
.docker pull usuario/imaxe:tag
docker pull bitnami/moodle:latest
docker pull mongodb
Alias de: docker image pull
docker pull alpine
docker image ls
docker image rm a_imaxe
docker image rm alpine
docker image ls
docker pull alpine
docker save -o alpinito.tar alpine
docker image rm alpine
docker image ls
docker load -i alpinito.tar
FROM debian:latest
LABEL maintainer="jfsanchez.es"
ARG _DIR="/home/user"
ARG _USER="user"
# Base, actualizar e instalar prerequisitos
RUN apt-get update; apt-get install -y locales ; apt-get dist-upgrade -y ; mkdir /var/run/sshd ; \
localedef -i es_ES -c -f UTF-8 -A /usr/share/locale/locale.alias en_ES.UTF-8 ; \
apt-get install -y curl wget gpg ca-certificates openssh-server openssh-client; rm -rf /var/lib/apt/lists/* ; dpkg-reconfigure --force openssh-server
ENV LANG=es_ES.utf8
#RUN update-rc.d ssh defaults ; systemctl enable ssh.service ; service ssh start
#Configurar usuario y home
RUN mkdir -p ${_DIR}/.ssh ; useradd ${_USER} -m -s /bin/bash ; chmod 0700 ${_DIR}/.ssh ; \
chown -R ${_USER}:${_USER} ${_DIR}
#WORKDIR /app
WORKDIR ${_DIR}
USER ${_USER}
#Generar llave SSH tipo DSA (mala práctica así)
RUN ssh-keygen -t ed25519 -N "" -C "user@docker" -f .ssh/id_ed25519 ; cp .ssh/id_ed25519.pub .ssh/authorized_keys ; chmod 644 .ssh/authorized_keys
USER root
RUN cp -r ${_DIR}/.ssh /root/ ; chown -R root:root /root/.ssh
EXPOSE 22
RUN service ssh start
CMD ["/usr/sbin/sshd", "-D"]
#ENTRYPOINT ["/etc/init.d/ssh", "start"]
Dockerfile
docker build -t jfsanchez/base:3 .
run
)docker run hello-world
docker ps -a
docker run --name flanders hello-world
docker ps -a
os contedores finalizados e en execución.docker rm IDENTIFICADOR_OU_NOME
-p PORTO_ANFITRIÓN:PORTO_CONTEDOR
docker run --name PORTOFINO \
-p 8080:80 \
--rm \
nginx:latest
http://localhost:8080
docker ps -a
Parámetro: -d
docker run --name websrv \
-p 8080:80 --rm \
-d \
nginx
Executa:
docker ps -a
docker stop NOME
docker ps -a
(-d)
docker run --name enginex -d -p 8080:80 nginx:latest
docker stop enginex
⛔ http://localhost:8080
docker ps
docker ps -a
docker start enginex
Opcións do parámetro
--restart
Crea un contedor (docker run) que...
docker run --name enginex \
-d \
-p 8080:80 \
--restart unless-stopped \
nginx:latest
Parámetro: --it
docker run --rm -it alpine sh
Pregunta rápida: Que facía --rm?
Solución: Borrar o contedor despois de que remate.
docker run --name blondie \
--env MARIADB_RANDOM_ROOT_PASSWORD=1 \
--restart unless-stopped -d mariadb:latest
docker logs blondie
docker exec -it blondie \
mariadb -hlocalhost -uroot -p'CONTRASINAL_ESCAPADA'
docker volume prune
docker volume create mariav
docker volume ls
docker run -p 9906:3306 --name ginger \
--env MARIADB_RANDOM_ROOT_PASSWORD=1 \
-v mariav:/var/lib/mysql \
--restart unless-stopped \
-d mariadb:latest
docker logs ginger
docker exec -it ginger \
mariadb -hlocalhost -uroot -p'CONTRASINAL_LOGS'
CREATE DATABASE contedor;
USE contedor;
CREATE TABLE volumen(
id INT auto_increment PRIMARY KEY,
nome VARCHAR(52));
INSERT INTO volumen VALUES(1,'mariav');
QUIT;
docker volume ls
docker stop ginger
docker rm ginger
docker ps -a
docker volume ls
docker run -p 9906:3306 --name ginger \
-v mariav:/var/lib/mysql --restart unless-stopped \
-d mariadb:latest
docker exec -it ginger \
mariadb -hlocalhost -uroot -p'CONTRASINAL_LOGS' contedor
SELECT * FROM volumen;
docker stop ginger
docker rm ginger
docker volume prune
docker volume ls
Porque non é anónimo
(foi creado explícitamente cun nome)
docker volume rm mariav
docker volume ls
-v /home/usuario/anfitrion:/ruta/docker
Exemplo
docker run --name exemplo \
-v /home/usuario/BBDD:/BBDD \
--env MARIADB_RANDOM_ROOT_PASSWORD=1 \
--restart unless-stopped \
-d mariadb:latest
docker exec -it exemplo bash
ls /BBDD
docker volume ls
docker volume prune
docker volume ls
Ruta por defecto dos volumes: /var/lib/docker/volumes/
Son moi útiles para actualizar o software:
docker network ls
--network X
-p PORTO_ANFITRION:PORTO_CONTEDOR
docker inspect ID_OU_NOME
Jose Sánchez
“Errare humanum est, sed perseverare diabolicum”Erros? / Errores? / Mistakes? →