You are on page 1of 6

Apasoft Training

Prácticas Docker
1. Nuestros primeros contenedores
• Vamos a crear nuestro primer contenedor

docker run hello-world


Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
ca4f61b1923c: Pull complete
Digest:
sha256:97ce6fa4b6cdc0790cda65fe7290b74cfebd9fa0c9b8c38e979330
d547d22ce1
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.
(amd64)
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:


www.apasoft-training.com
apasoft.training@gmail.com 1
Apasoft Training

https://docs.docker.com/engine/userguide/
• Comprobar que el contenedor no está activo, ya que se cierra en cuanto
sal el mensaje

docker ps
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
• Comprobar que el contenedor se ha creado, pero que está parado

docker ps -a
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
0e7ef0959d21 hello-world "/hello"
32 minutes ago Exited (0) 32 minutes ago
• Comprobar que existe la imagen

docker images
REPOSITORY TAG IMAGE ID
CREATED SIZE
hello-world latest f2a91732366c
3 months ago 1.85kB
• Creamos un nuevo contenedor a partir de la imagen y vemos que existe

docker run hello-world

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.
(amd64)
3. The Docker daemon created a new container from that
image which runs the
executable that produces the output you are currently
reading.

www.apasoft-training.com
apasoft.training@gmail.com 2
Apasoft Training

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/

docker ps -a
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
ac6d243d4bcc hello-world "/hello"
5 seconds ago Exited (0) 4 seconds ago
loving_jennings
0e7ef0959d21 hello-world "/hello"
37 minutes ago Exited (0) 36 minutes ago

• Creamos un nuevo contenedor basado en otra imagen de Docker Hub


denominada busybox, que es un contenedor con un cierto número de
utilidades

docker run busybox


Unable to find image 'busybox:latest' locally
latest: Pulling from library/busybox
d070b8ef96fc: Pull complete
Digest:
sha256:2107a35b58593c58ec5f4e8f2c4a70d195321078aebfadfbfb2
23a2ff4a4ed21
Status: Downloaded newer image for busybox:latest
• Comprobamos el nuevo contenedor

www.apasoft-training.com
apasoft.training@gmail.com 3
Apasoft Training

docker ps -a
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
f639beed83d0 busybox "sh"
59 seconds ago Exited (0) 58 seconds ago
nifty_vaughan
ac6d243d4bcc hello-world "/hello"
4 minutes ago Exited (0) 4 minutes ago
loving_jennings
0e7ef0959d21 hello-world "/hello"
41 minutes ago Exited (0) 41 minutes ago
festive_davinci
• Comprobar que existe la imagen

docker images
REPOSITORY TAG IMAGE ID
CREATED SIZE
busybox latest f6e427c148a7
2 weeks ago 1.15MB
hello-world latest f2a91732366c
3 months ago 1.85kB
• Visualizar solo las ids de los contenedores

docker ps -aq
f639beed83d0
ac6d243d4bcc
0e7ef0959d21
• Ver los dos últimos contenedores lanzados

docker ps -a -n 2
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
f639beed83d0 busybox "sh"
15 minutes ago Exited (0) 15 minutes ago
nifty_vaughan
ac6d243d4bcc hello-world "/hello"
19 minutes ago Exited (0) 19 minutes ago
loving_jennings
• Comprobar el espacio utilizado por los contenedores creados

www.apasoft-training.com
apasoft.training@gmail.com 4
Apasoft Training

docker ps -a -s
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES SIZE
f639beed83d0 busybox "sh"
15 hours ago Exited (0) 15 hours ago
nifty_vaughan 0B (virtual 1.15MB)
ac6d243d4bcc hello-world "/hello"
15 hours ago Exited (0) 15 hours ago
loving_jennings 0B (virtual 1.85kB)
0e7ef0959d21 hello-world "/hello"
16 hours ago Exited (0) 16 hours ago
festive_davinci 0B (virtual 1.85kB)
• También podemos usar la opción -f para filtrar por algún dato concreto,
por ejemplo, por el nombre. Busca por el contenido dentro del texto.
• Ejemplo. Teniendo estos contenedores

docker ps -a
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
f639beed83d0 busybox "sh" 17
hours ago Exited (0) 17 hours ago
nifty_vaughan
ac6d243d4bcc hello-world "/hello" 17
hours ago Exited (0) 17 hours ago
loving_jennings
0e7ef0959d21 hello-world "/hello" 18
hours ago Exited (0) 18 hours ago
festive_davinci

• Si queremos saber los que tienen la palabra “davinci” en el nombre

docker ps -a -f name=davinci
CONTAINER ID IMAGE COMMAND
CREATED STATUS PORTS
NAMES
0e7ef0959d21 hello-world "/hello"
18 hours ago Exited (0) 18 hours ago
festive_davinci
• O los que tengan una “y” en el nombre

docker ps -a -f name=y

www.apasoft-training.com
apasoft.training@gmail.com 5
Apasoft Training

CONTAINER ID IMAGE COMMAND


CREATED STATUS PORTS
NAMES
f639beed83d0 busybox "sh"
17 hours ago Exited (0) 17 hours ago
nifty_vaughan

www.apasoft-training.com
apasoft.training@gmail.com 6

You might also like