Main commands for docker containers

  • $ docker search [container-image]: search all docker container images available for the download
  • $ docker ps -a: list all dockers
  • $ docker run [container-image]: run a new docker container:
    • -d: run the container in background
    • --name [container-name]: set a name for the docker container
    • --net [network-name]: set the network for the docker container
    • --ip [container-ip-address]: set a custom IP address for the docker container located in a docker network previously created
    • -p [port]:[port]: port forwarding
  • $ docker start [docker-id]: start the selected container
  • $ docker stop [docker-id]: stop the selected container
  • $ docker exec -it [docker-id] /bin/bash: run the selected container opening the bash
  • $ docker exec -it [docker-id] [command]: run a command into the specified container
  • $ docker inspect [docker-id]: show docker container’s information

Pre-built commands

  • Install and run a container with installed Arch Linux and named as arch:

    $ docker run -it --name arch archlinux /bin/bash
  • Run an installed container called arch:

    $ docker exec -it arch /bin/bash
  • This command creates a docker container called mosquitto-broker using eclipse-mosquitto as container image. Furthermore the container is running in background, a custom IP address and a custom network are assigned and the port 1883 is forwarded:

    $ docker run -d --name mosquitto-broker --net sharemetrics-network --ip -p 1883:1883 eclipse-mosquitto

Docker Network

  • For creating a network for docker containers run:
    $ docker network create --subnet=[network-ip]/[CIDR] [network-name]
  • For example:
    $ docker network create --subnet= sharemetrics-network
  • In this case, for example, a container located in sharemetrics network could have the IP address