Docker

Table of Contents


  • Official Documentation
  • Images
    • postgres
      • https://github.com/docker-library/postgres
      • https://docs.docker.com/engine/examples/postgresql_service/
      • https://docs.docker.com/samples/library/postgres/
      • https://hub.docker.com/_/postgres
    • luigi
      • https://hub.docker.com/r/pysysops/luigid
      • https://hub.docker.com/r/stockport/luigid
      • https://hub.docker.com/r/stockport/luigi-taskrunner
      • https://hub.docker.com/r/mada/luigid
      • https://hub.docker.com/r/spiside/luigi
    • redis
      • https://hub.docker.com/_/redis
    • memcached
      • https://hub.docker.com/_/memcached
    • cassandra
      • https://hub.docker.com/_/cassandra
    • neo4j
      • https://hub.docker.com/_/neo4j
    • arangodb
      • https://hub.docker.com/_/arangodb
    • rethinkdb
      • https://hub.docker.com/_/rethinkdb
    • orientdb
      • https://hub.docker.com/_/orientdb
    • cratedb
      • https://hub.docker.com/_/crate
    • rabbitmq
      • https://hub.docker.com/_/rabbitmq
    • kafka
      • https://hub.docker.com/r/spotify/kafka
    • elasticsearch
      • https://hub.docker.com/_/elasticsearch
    • logstash
      • https://hub.docker.com/_/logstash
    • kibana
      • https://hub.docker.com/_/kibana
    • prometheus
      • https://hub.docker.com/r/prom/prometheus
    • influxdb
      • https://hub.docker.com/_/influxdb
      • https://hub.docker.com/_/influxdata-influxdb
    • telegraf
      • https://hub.docker.com/_/telegraf
    • chronograf
      • https://hub.docker.com/_/chronograf
    • fluentd
      • https://hub.docker.com/_/fluentd
    • datadog agent
      • https://hub.docker.com/_/datadog-agent
    • haproxy
      • https://hub.docker.com/_/haproxy
    • jenkins
      • https://hub.docker.com/_/jenkins
    • sonarqube
      • https://hub.docker.com/_/sonarqube
    • erlang
      • https://hub.docker.com/_/erlang
    • rust
      • https://hub.docker.com/_/rust

Cleanup:

$ docker stop $(docker ps -a -q)
$ docker rm -f $(docker ps -a -q)
$ docker rmi -f $(docker images -q)

List running containers:

$ docker ps

Lists images

$ docker imagess

Docker Run

$ docker run -it --name <NAME> <IMAGE NAME> <ARGS>

    -i interactive
    -t terminal
    -v FULL_VOLUME_PATH

    -v ${PWD}/.:/home/test_directory

    copies everything in ./ on local to /home/test_directory in the container

    -p HOST_PORT:CONTAINER_PORT

    -p 1234:80
    maps port 1234 to port 80 inside the container

$ docker help run

Usage:  docker run [OPTIONS] IMAGE [COMMAND] [ARG...]

Run a command in a new container

Options:
      --add-host list                  Add a custom host-to-IP mapping (host:ip)
  -a, --attach list                    Attach to STDIN, STDOUT or STDERR
  -d, --detach                         Run container in background and print container ID
      --detach-keys string             Override the key sequence for detaching a container
      --entrypoint string              Overwrite the default ENTRYPOINT of the image
  -e, --env list                       Set environment variables
      --env-file list                  Read in a file of environment variables
      --expose list                    Expose a port or a range of ports
      --help                           Print usage
  -h, --hostname string                Container host name
      --init                           Run an init inside the container that forwards signals and reaps processes
  -i, --interactive                    Keep STDIN open even if not attached
      --ip string                      IPv4 address (e.g., 172.30.100.104)
      --ip6 string                     IPv6 address (e.g., 2001:db8::33)
      --link list                      Add link to another container
      --link-local-ip list             Container IPv4/IPv6 link-local addresses
      --log-driver string              Logging driver for the container
      --log-opt list                   Log driver options
      --mount mount                    Attach a filesystem mount to the container
      --name string                    Assign a name to the container
      --network string                 Connect a container to a network (default "default")
      --network-alias list             Add network-scoped alias for the container
      --no-healthcheck                 Disable any container-specified HEALTHCHECK
      --oom-kill-disable               Disable OOM Killer
      --pid string                     PID namespace to use
  -p, --publish list                   Publish a container's port(s) to the host
  -P, --publish-all                    Publish all exposed ports to random ports
      --rm                             Automatically remove the container when it exits
      --runtime string                 Runtime to use for this container
      --stop-signal string             Signal to stop a container (default "SIGTERM")
      --tmpfs list                     Mount a tmpfs directory
  -t, --tty                            Allocate a pseudo-TTY
      --ulimit ulimit                  Ulimit options (default [])
  -u, --user string                    Username or UID (format: <name|uid>[:<group|gid>])
      --userns string                  User namespace to use
  -v, --volume list                    Bind mount a volume
  -w, --workdir string                 Working directory inside the container

EXITING

  • close terminal, process and container will still run
  • ctrl-p ctrl-q detaches the terminal from the container
  • stop the process

DOCKER ATTACH

$ docker attach <CONTAINER NAME>

DOCKER START

$ docker ps -a
lists all containers, including those not running

if a container is not running (stopped) it can be
started with

$ docker start <CONTAINER_NAME>

DOCKER EXEC

$ docker exec -it <CONTAINER NAME> <COMMAND>

runs another process inside a container

DOCKER STOP

$ docker stop <CONTAINER NAME>

DOCKER RM

$ docker rm <CONTAINER NAME>*

removes a container

DOCKER RMI

removes docker images

DOCKER INSPECT

$ docker inspect <CONTAINER NAME>

$ docker stats
$ docker system df
$ docker system events
$ docker system info
$ docker system prune

DOCKER-COMPOSE

Define and run multi-container applications with Docker.

Usage:
  docker-compose [-f <arg>...] [options] [COMMAND] [ARGS...]
  docker-compose -h|--help

Options:
  -f, --file FILE             Specify an alternate compose file
                              (default: docker-compose.yml)
  -p, --project-name NAME     Specify an alternate project name
                              (default: directory name)
  --verbose                   Show more output
  --log-level LEVEL           Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  --no-ansi                   Do not print ANSI control characters
  -v, --version               Print version and exit
  -H, --host HOST             Daemon socket to connect to

  --tls                       Use TLS; implied by --tlsverify
  --tlscacert CA_PATH         Trust certs signed only by this CA
  --tlscert CLIENT_CERT_PATH  Path to TLS certificate file
  --tlskey TLS_KEY_PATH       Path to TLS key file
  --tlsverify                 Use TLS and verify the remote
  --skip-hostname-check       Don't check the daemon's hostname against the
                              name specified in the client certificate
  --project-directory PATH    Specify an alternate working directory
                              (default: the path of the Compose file)
  --compatibility             If set, Compose will attempt to convert deploy
                              keys in v3 files to their non-Swarm equivalent

Commands:
  build              Build or rebuild services
  bundle             Generate a Docker bundle from the Compose file
  config             Validate and view the Compose file
  create             Create services
  down               Stop and remove containers, networks, images, and volumes
  events             Receive real time events from containers
  exec               Execute a command in a running container
  help               Get help on a command
  images             List images
  kill               Kill containers
  logs               View output from containers
  pause              Pause services
  port               Print the public port for a port binding
  ps                 List containers
  pull               Pull service images
  push               Push service images
  restart            Restart services
  rm                 Remove stopped containers
  run                Run a one-off command
  scale              Set number of containers for a service
  start              Start services
  stop               Stop services
  top                Display the running processes
  unpause            Unpause services
  up                 Create and start containers
  version            Show the Docker-Compose version information