Pierdo mis datos cuando el contenedor sale

Resuelto iman asked hace 10 años • 11 respuestas

A pesar del tutorial interactivo y las preguntas frecuentes de Docker, pierdo mis datos cuando se cierra el contenedor.

Instalé Docker como se describe aquí: http://docs.docker.io/en/latest/installation/ubuntulinux sin ningún problema en ubuntu 13.04.

Pero pierde todos los datos cuando sale.

iman@test:~$ sudo docker version
Client version: 0.6.4 
Go version (client): go1.1.2 
Git commit (client): 2f74b1c 
Server version: 0.6.4 
Git commit (server): 2f74b1c 
Go version (server): go1.1.2 
Last stable version: 0.6.4 


iman@test:~$ sudo docker run ubuntu ping
2013/10/25 08:05:47 Unable to locate ping 
iman@test:~$ sudo docker run ubuntu apt-get install ping
Reading package lists... 
Building dependency tree... 
The following NEW packages will be installed: 
  iputils-ping 
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded. 
Need to get 56.1 kB of archives. 
After this operation, 143 kB of additional disk space will be used. 
Get:1 http://archive.ubuntu.com/ubuntu/ precise/main iputils-ping amd64 3:20101006-1ubuntu1 [56.1 kB] 
debconf: delaying package configuration, since apt-utils is not installed 
Fetched 56.1 kB in 0s (195 kB/s) 
Selecting previously unselected package iputils-ping. 
(Reading database ... 7545 files and directories currently installed.) 
Unpacking iputils-ping (from .../iputils-ping_3%3a20101006-1ubuntu1_amd64.deb) ... 
Setting up iputils-ping (3:20101006-1ubuntu1) ... 
iman@test:~$ sudo docker run ubuntu ping
2013/10/25 08:06:11 Unable to locate ping 
iman@test:~$ sudo docker run ubuntu touch /home/test
iman@test:~$ sudo docker run ubuntu ls /home/test
ls: cannot access /home/test: No such file or directory 

También lo probé con sesiones interactivas con el mismo resultado. ¿Olvidé algo?

EDITAR: IMPORTANTE PARA NUEVOS USUARIOS DE DOCKER

Como dijeron @ mohammed-noureldin y otros, en realidad este NO es un contenedor que sale . Cada vez simplemente crea un nuevo contenedor.

iman avatar Oct 25 '13 15:10 iman
Aceptado

Debe confirmar los cambios que realiza en el contenedor y luego ejecutarlo. Prueba esto:

sudo docker pull ubuntu

sudo docker run ubuntu apt-get install -y ping

Luego obtenga la identificación del contenedor usando este comando:

sudo docker ps -l

Confirmar cambios en el contenedor:

sudo docker commit <container_id> iman/ping 

Luego ejecuta el contenedor:

sudo docker run iman/ping ping www.google.com

Esto debería funcionar.

Unferth avatar Oct 25 '2013 09:10 Unferth

Cuando utiliza docker runpara iniciar un contenedor, en realidad crea un nuevo contenedor basado en la imagen que ha especificado.

Además de las otras respuestas útiles aquí, tenga en cuenta que puede reiniciar un contenedor existente después de que salió y sus cambios seguirán ahí.

docker start f357e2faab77 # restart it in the background
docker attach f357e2faab77 # reattach the terminal & stdin
ZeissS avatar Oct 27 '2013 09:10 ZeissS

Existen las siguientes formas de conservar los datos del contenedor:

  1. Volúmenes acoplables

  2. compromiso de Docker

    a) crear un contenedor a partir de la imagen de ubuntu y ejecutar una terminal bash.

       $ docker run -i -t ubuntu:14.04 /bin/bash
    

    b) Dentro del terminal instale curl

       # apt-get update
       # apt-get install curl
    

    c) Salir de la terminal de contenedores

       # exit
    

    d) Tome nota de la identificación de su contenedor ejecutando el siguiente comando:

       $ docker ps -a
    

    e) guardar el contenedor como nueva imagen

       $ docker commit <container_id> new_image_name:tag_name(optional)
    

    f) verifique que pueda ver su nueva imagen con curl instalado.

       $ docker images           
    
       $ docker run -it new_image_name:tag_name bash
          # which curl
            /usr/bin/curl
    
kalyani chaudhari avatar May 17 '2016 08:05 kalyani chaudhari

Además de la respuesta de Unferth , se recomienda crear un Dockerfile .

En un directorio vacío, cree un archivo llamado "Dockerfile" con el siguiente contenido.

FROM ubuntu
RUN apt-get install ping
ENTRYPOINT ["ping"]

Cree una imagen usando Dockerfile . Usemos una etiqueta para no tener que recordar el número de imagen hexadecimal.

$ docker build -t iman/ping .

Y luego ejecute la imagen en un contenedor.

$ docker run iman/ping stackoverflow.com
salathe avatar Oct 25 '2013 09:10 salathe