Bien, vamos a continuar probando cosas ahora que ya hemos conseguido tener una imagen funcionando.
Comprobamos las imágenes que tenemos disponibles:
alberto@ansible-master:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu latest 6a2f32de169d 5 days ago 117.2 MB
hello-world latest 48b5124b2768 3 months ago 1.84 kB
docker tag <image> <name>: Sirve para dar una etiqueta a una imagen instalada.
Es interesante definir una etiqueta personalizada que haga referencia a una imagen instalada en su sistema. Esto puede venir bien para tener un poco más de organización cuando se utilizan muchas imágenes, más cuando son del mismo sistema.
alberto@ansible-master:~$ docker tag 48b5124b2768 hola-mundo
Verificamos:
alberto@ansible-master:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
sysbench latest 2961caa2662b 4 hours ago 127.4 MB
pwgen latest 7de10fd8ab39 4 hours ago 4.849 MB
alberto test 7f434c386b9e 2 days ago 97.34 MB
ubuntu alberto a47c7de1ccb6 2 days ago 121.3 MB
ubuntu latest 6a2f32de169d 7 days ago 117.2 MB
debian jessie 8cedef9d7368 4 weeks ago 123.4 MB
alpine 3.4 245f7a86c576 6 weeks ago 4.807 MB
hello-world latest 48b5124b2768 3 months ago 1.84 kB
hola-mundo latest 48b5124b2768 3 months ago 1.84 kB
docker start <image>: Sirve para arrancar un contenedor
alberto@ansible-master:~$ docker start ac7b774bb732
ac7b774bb732
docker stop <container>: Sirve para parar un contenedor
alberto@ansible-master:~$ docker stop ac7b774bb732
ac7b774bb732
docker commit <container> <image>: Sirve para guardar un contenedor como una imagen
alberto@ansible-master:~$ docker commit ac7b774bb732 ubuntu:alberto
sha256:4eec2299f8415d4d7f88171919c3f09e9ed85754e1f3ba40e81a3dde8d23ac39
Comprobamos:
alberto@ansible-master:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu alberto 4eec2299f841 7 seconds ago 117.2 MB
sysbench latest 2961caa2662b 5 hours ago 127.4 MB
pwgen latest 7de10fd8ab39 5 hours ago 4.849 MB
alberto test 7f434c386b9e 2 days ago 97.34 MB
<none> <none> a47c7de1ccb6 2 days ago 121.3 MB
ubuntu latest 6a2f32de169d 7 days ago 117.2 MB
debian jessie 8cedef9d7368 4 weeks ago 123.4 MB
alpine 3.4 245f7a86c576 6 weeks ago 4.807 MB
hola-mundo latest 48b5124b2768 3 months ago 1.84 kB
hello-world latest 48b5124b2768 3 months ago 1.84 kB
docker save <image> > <dir>: Sirve para exportar la imagen a fichero
alberto@ansible-master:~$ docker save ubuntu:alberto > /tmp/ubuntu.alberto.tar
Comprobamos:
alberto@ansible-master:~$ tar tvf /tmp/ubuntu.alberto.tar
-rw-r--r-- 0/0 3483 2016-04-20 16:55 4eec2299f8415d4d7f88171919c3f09e9ed85754e1f3ba40e81a3dde8d23ac39.json
drwxr-xr-x 0/0 0 2016-04-20 16:55 74f82876bc3a2bcd96640d7473dff037fe99bae07c7dd9ad142a2fd2178968fe/
-rw-r--r-- 0/0 3 2016-04-20 16:55 74f82876bc3a2bcd96640d7473dff037fe99bae07c7dd9ad142a2fd2178968fe/VERSION
-rw-r--r-- 0/0 388 2016-04-20 16:55 74f82876bc3a2bcd96640d7473dff037fe99bae07c7dd9ad142a2fd2178968fe/json
-rw-r--r-- 0/0 121239552 2016-04-20 16:55 74f82876bc3a2bcd96640d7473dff037fe99bae07c7dd9ad142a2fd2178968fe/layer.tar
drwxr-xr-x 0/0 0 2016-04-20 16:55 7fb54cf7f1a5ab16942b4461ecfd51ab4d2a08613e00dc58832ced0233c0eef6/
-rw-r--r-- 0/0 3 2016-04-20 16:55 7fb54cf7f1a5ab16942b4461ecfd51ab4d2a08613e00dc58832ced0233c0eef6/VERSION
-rw-r--r-- 0/0 464 2016-04-20 16:55 7fb54cf7f1a5ab16942b4461ecfd51ab4d2a08613e00dc58832ced0233c0eef6/json
-rw-r--r-- 0/0 15872 2016-04-20 16:55 7fb54cf7f1a5ab16942b4461ecfd51ab4d2a08613e00dc58832ced0233c0eef6/layer.tar
drwxr-xr-x 0/0 0 2016-04-20 16:55 982c5bfe381b11e583cbc1d1f0aedef4143f8ef28707e729f03c7fe88a6e5475/
-rw-r--r-- 0/0 3 2016-04-20 16:55 982c5bfe381b11e583cbc1d1f0aedef4143f8ef28707e729f03c7fe88a6e5475/VERSION
-rw-r--r-- 0/0 464 2016-04-20 16:55 982c5bfe381b11e583cbc1d1f0aedef4143f8ef28707e729f03c7fe88a6e5475/json
-rw-r--r-- 0/0 5632 2016-04-20 16:55 982c5bfe381b11e583cbc1d1f0aedef4143f8ef28707e729f03c7fe88a6e5475/layer.tar
drwxr-xr-x 0/0 0 2016-04-20 16:55 e284a9bc939e269d3cadbd9adeb222380b763569a51c43c956994f4dc263fbdd/
-rw-r--r-- 0/0 3 2016-04-20 16:55 e284a9bc939e269d3cadbd9adeb222380b763569a51c43c956994f4dc263fbdd/VERSION
-rw-r--r-- 0/0 1043 2016-04-20 16:55 e284a9bc939e269d3cadbd9adeb222380b763569a51c43c956994f4dc263fbdd/json
-rw-r--r-- 0/0 3072 2016-04-20 16:55 e284a9bc939e269d3cadbd9adeb222380b763569a51c43c956994f4dc263fbdd/layer.tar
drwxr-xr-x 0/0 0 2016-04-20 16:55 f848e53091079995d62b1ce5980bc17b04a337a9f02819dd452e28fa22f4b819/
-rw-r--r-- 0/0 3 2016-04-20 16:55 f848e53091079995d62b1ce5980bc17b04a337a9f02819dd452e28fa22f4b819/VERSION
-rw-r--r-- 0/0 464 2016-04-20 16:55 f848e53091079995d62b1ce5980bc17b04a337a9f02819dd452e28fa22f4b819/json
-rw-r--r-- 0/0 11776 2016-04-20 16:55 f848e53091079995d62b1ce5980bc17b04a337a9f02819dd452e28fa22f4b819/layer.tar
-rw-r--r-- 0/0 511 1970-01-01 01:00 manifest.json
-rw-r--r-- 0/0 90 1970-01-01 01:00 repositories
docker load < <file>: Permite importar un fichero y registrarlo como imagen
alberto@ansible-master:~$ docker load < /tmp/ubuntu.alberto.tar
Loaded image: ubuntu:alberto
docker rmi <nombre>: Permite borrar una imagen del registro local
alberto@ansible-master:~$ docker rmi hola-mundo
Untagged: hola-mundo:latest
También puede usarse el <IMAGE ID> para definir la imagen a borrar
alberto@ansible-master:~$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
ubuntu alberto 4eec2299f841 6 minutes ago 117.2 MB
sysbench latest 2961caa2662b 5 hours ago 127.4 MB
pwgen latest 7de10fd8ab39 5 hours ago 4.849 MB
alberto test 7f434c386b9e 2 days ago 97.34 MB
<none> <none> a47c7de1ccb6 2 days ago 121.3 MB
alberto@ansible-master:~$ docker rmi a47c7de1ccb6
Deleted: sha256:a47c7de1ccb68335b874e872e7209e8e571a26928c2467463e3591a4beb47217
Deleted: sha256:30225fffea5bbe3d85ed2d48fc60d12201a3425cdaea194a9399e9febfaa5e02