IMAGENES Y CONTENEDORES EN DOCKER



IMÁGENES DOCKER
Las imágenes de docker están ubicadas en:
Buscar Imágenes
# docker search ubuntu
 Descargar una imagen
# docker pull ubuntu
 
Buscar docker por tag determinado
# docker search ubuntu:20.04
 
Descargar imagen por tag determinado
# docker pull ubuntu:20.04
 
PRIMER HELLO WORLD CONTAINER

INICIALIZAR CONTENEDORES
# DOCKER RUN
 
Options
--interactive , -i                                                Keep STDIN open even if not attached
--tty , -t                                                               Allocate a pseudo-TTY
--name string                           Assign a name to the container
-d, --detach                                Run container in background and print container ID
-p, --publish list                          Publish a container's port(s) to the host (default [])
 
Comando para ejecutar y descargar una imagen
# docker run hello-world
Ejecutar container “ubuntu” y ejecutar comando “ls”
# docker run ubuntu ls
Ejecutar container “ubuntu” e ingresar al bash
# docker run -i -t ubuntu bash
# docker run -it ubuntu
Ejecutar n contenedor con un nombre específico e interactivo
# docker run --name BesoftTI -it ubuntu
 
Para salir del contenedor sin detenerlo ingresar: ctrl + p + q
 
MOSTRAR CONTENEDORES
# DOCKER PS
 
Options:
  -a, --all             Show all containers (default shows just running)
  -n, --last int        Show n last created containers (includes all states) (default -1)
  -l, --latest          Show the latest created container (includes all states)
  -q, --quiet           Only display numeric IDs
  -s, --size            Display total file sizes
 
 
Comando para mostrar los contenedores
# docker ps
Comando para mostrar todos los contenedores ejecutados
# docker ps –a
 
GESTIÓN DE IMAGES DOCKER
# DOCKER IMAGES
Options:
  -a, --all               Show all images (default hides intermediate images)
  -f, --filter filter   Filter output based on conditions provided
      --help            Print usage
  -q, --quiet           Only show numeric IDs
 
 
LEVANTAR CONTENEDORES
# DOCKER START
 
Levantar un contenedor por su id
# docker start 62983611cf88
 
Levantar un contenedor por su id (solo es necesario los primeros 2 digitos del ID)
# docker start 629
 
 
 
INGRESAR A N CONTENEDOR
# DOCKER ATTACH
 
Ingresar a un contenedor previamente levantado
# docker attach 62983611cf88
 
DETENER CONTENEDOR
# DOCKER STOP
 
Detener un contenedor docker (solo es necesario las3 primeros dígitos del ID del contenedor)
# docker stop 724
 
CREAR UNA NUEVA IMAGEN A PARTIR DE UN CONTENEDOR
# DOCKER COMMIT
Options:
  -a, --author string    Author (e.g., "John Hannibal Smith <hannibal@a-team.com>")
  -c, --change list      Apply Dockerfile instruction to the created image (default [])
      --help             Print usage
  -m, --message string   Commit message
  -p, --pause            Pause container during commit (default true)
 
Crear nueva imagen a partir del contenedor con ID 2d8d6193b63d, el nombre de la nueva imagen será ubuntubesoft
# docker commit 2d8d6193b63d ubuntubesoft
 
Compilar nueva imagen, se le pasa la instrucción CMD y se expone el puerto 85 y con nombre final ubuntu-apache2
# docker commit --change='CMD ["apache2ctl", "-D FOREGROUND"]' -c "EXPOSE 85" 3fef94e1ecd6 ubuntu-apache2
 
apachectl -DFOREGROUND runs in the foreground. In other words, it blocks the progress of your entrypoint script until apachectl exits