Prácticas Docker: 1. Nuestros Primeros Contenedores
Prácticas Docker: 1. Nuestros Primeros Contenedores
Prácticas Docker: 1. Nuestros Primeros Contenedores
Prácticas Docker
1. Nuestros primeros contenedores
• Vamos a crear nuestro primer contenedor
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/
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
www.apasoft-training.com
apasoft.training@gmail.com 2
Apasoft Training
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
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
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
www.apasoft-training.com
apasoft.training@gmail.com 6