Docker and CentOS 7 (Part I)

Docker is a quite new technology of software virtualization and step forward of virtual environment. Docker is different from classical virtual machines (VMs). More details about can be found in official docker documentation. This become popular last years and this may be important for WEB programs developers, system administrators or system network engineers. I plan to publish series short articles about Docker technology tips. Some tips are developed by me, some not. The current one will be about aliases and functions in BASH. Lets go starting.

Docker is a software technology providing containers, promoted by the company Docker, Inc. Docker provides an additional layer of abstraction and automation of operating-system-level virtualization on Windows and Linux. Docker uses the resource isolation features of the Linux kernel to allow independent “containers” to run within a single Linux instance, avoiding the overhead of starting and maintaining virtual machines (VMs).

These articles are dedicated to Docker installed by CentOS 7 Linux operating system. The detailed explanation how setup Docker by CentOS you can easily find in official docker documentation.

Docker controlled by command line interface and commands are long. There is a way to increase productivity by using aliases and functions in BASH. Here is some…

To simplify your life the current user CAN be added to the docker group on your system.


  • Get latest container ID

    $ alias dl="docker ps -l -q"

  • Get container process

    $ alias dps="docker ps"

  • Get process included stop container

    $ alias dpa="docker ps -a"

  • Get images

    $ alias di="docker images"

  • Stop and Remove all containers

    $ alias drmf='docker stop $(docker ps -a -q) \
    && docker rm $(docker ps -a -q)'

  • Run deamonized container, e.g., $dkd base /bin/echo hi_there

    $ alias dkd="docker run -d -P"
    *Note: This alias may be recreated as function. See below

  • Run interactive container, e.g., $dki base /bin/bash

    $ alias dki='docker run -i -t -P'
    *Note: This alias may be recreated as function. See below

  • Execute interactive container, e.g., $dex base /bin/bash

    $ alias dex="docker exec -i -t"


  • Stop all containers

    $ dstop() { docker stop $(docker ps -a -q); }

  • Start all containers

    $ dstart() { docker start $(docker ps -a -q); }

  • Remove all containers

    $ drm() { docker rm $(docker ps -a -q); }

  • Remove all images

    $ dri() { docker rmi $(docker images -q); }

  • Dockerfile build, e.g., $dbu user/test

    $ dbu() { docker build -t=$1 .; }

  • Show all alias related docker

    $ daliases() { alias | grep 'docker' | \
      sed "s/^\([^=]*\)=\(.*\)/\1 => \2/"| \
      sed "s/['|\']//g" | sort; }

  • Bash into running container

    $ dbash() { docker exec -it $(docker ps -aqf "name=$1") bash; }

  • Run deamonized container, e.g., $dkd base

    $ dkd() { docker run --name $1 -d -P $1; }

  • Run interactive container, e.g., $dki base /bin/bash

    $ dki() { docker run --name $1 -i -t -P $1 $2; }

The next part is on the way…

Thanks for your time…

comments powered by Disqus