Commands
List all the images
docker imagesDownload image
# docker pull [image]
docker pull mysqlDelete image
# docker image rm [image]
# docker image rm [image]:[tag]
docker image rm mysql
docker image rm mysql:latest
docker image rm mysql:16Create a container with the image
With random container name
It will generate an ID to the container.
# docker container create [image]
# docker create [image]
docker create mysqlId generated:
a6e16354239fc76b4cc89216bfe46f0260500a7e798d62e319af213345bb13c8With custom container name
docker create --name monguito mongoId generated:
e1d70ca8719dcf07987eae76bac9a621d4531e9c9b8bdf8328b647e649d3f438Start a container
Using the ID of the container
# docker start [container_id]
docker start a6e16354239fc76b4cc89216bfe46f0260500a7e798d62e319af213345bb13c8Using the custom name of the container
docker start monguito
docker ps # we will see the container runningUsing environment variables
For example, to create a mongodb container with specific user and password, to then use an app to connect to it, we use the env variable described in mongodb hub:
https://hub.docker.com/_/mongo
Each image has different ways to configure
docker create -p27017:27017 --name monguito -e MONGO_INITDB_ROOT_USERNAME=nico -e MONGO_INITDB_ROOT_PASSWORD=password mongoStatus of containers running 
docker psCONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS       NAMES
a6e16354239f   mysql     "docker-entrypoint.s…"   4 minutes ago   Up 2 seconds   27017/tcp   pedantic_rubinStop a container
docker stop a6e16354239f
docker ps
# There is no one container runningList of containers started and off
List all the containers in system.
docker ps --all
docker ps -aCONTAINER ID   IMAGE     COMMAND                  CREATED        STATUS                    PORTS     NAMES
a6e16354239f   mysql     "docker-entrypoint.s…"   22 hours ago   Exited (0) 22 hours ago             pedantic_rubinDelete a container
Using name
docker rm pedantic_rubin
docker ps -a #container deletedExpose a container in a host port
Custom port
# docker create -p[port_in_host]:[port_in_container] --name [name] [image]
docker create -p27017:27017 --name monguito mongodocker start monguito
docker psCONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                           NAMES
6c97203a3708   mongo     "docker-entrypoint.s…"   2 minutes ago   Up 2 seconds   0.0.0.0:27017->27017/tcp, :::27017->27017/tcp   monguitoRandom port
# docker create -p[port_in_container] --name [name] [image]
docker create -p27017 --name manguito mongodocker start manguito
docker psCONTAINER ID   IMAGE     COMMAND                  CREATED         STATUS         PORTS                                           NAMES
2bdec62e384c   mongo     "docker-entrypoint.s…"   6 seconds ago   Up 1 second    0.0.0.0:32768->27017/tcp, :::32768->27017/tcp   manguitoCheck logs of container
docker logs monguitoOr to stay watching those logs:
docker logs --follow monguitoDownload the image, create and start the container
With logs view, random data
docker run mongoWithout logs view, detach mode and random data
docker run -d mongoUnable to find image 'mongo:latest' locally
latest: Pulling from library/mongo
57c139bbda7e: Pull complete 
2a7c884ecb1c: Pull complete 
ddcbc3e219f6: Pull complete 
347abad2978b: Pull complete 
33ad7d6a71b8: Pull complete 
46b764746687: Pull complete 
0d22e1cb5ef2: Pull complete 
fef1dc21c099: Pull complete 
Digest: sha256:175ee5c400f24d2766cea492b4986851b4e7ec75fc08e354673149b86488019c
Status: Downloaded newer image for mongo:latest
309059638da6dc66af6cd40312bef60c36b1b7b6056bc6b3f38d824ab39b2e26It generates our container ID:
309059638da6dc66af6cd40312bef60c36b1b7b6056bc6b3f38d824ab39b2e26docker ps          
CONTAINER ID   IMAGE     COMMAND                  CREATED              STATUS              PORTS       NAMES
309059638da6   mongo     "docker-entrypoint.s…"   About a minute ago   Up About a minute   27017/tcp   crazy_thompsonWithout logs view and custom data
docker run -d --name monguito -p27017:27017 mongo
#a146ef22b6bb96889a273d8037f4613eefb5519e063faa8f84555e1fb43072e8docker ps                                        
CONTAINER ID   IMAGE     COMMAND                  CREATED              STATUS              PORTS                                           NAMES
a146ef22b6bb   mongo     "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:27017->27017/tcp, :::27017->27017/tcp   monguitoInteract with networks
List networks
docker network lsNETWORK ID     NAME      DRIVER    SCOPE
b17449f934b1   bridge    bridge    local
6b89bd5bc050   host      host      local
fdc75e667bd0   none      null      localCreate a network
# docker network create [nombre]
docker network create miredNETWORK ID     NAME      DRIVER    SCOPE
b17449f934b1   bridge    bridge    local
6b89bd5bc050   host      host      local
9cbcc9aa1f95   mired     bridge    local
fdc75e667bd0   none      null      localDelete a network
docker network rm miredLast updated