Docker. Set frequently used commands to alias "with explanation"

Introduction

The Docker command I often use is set to alias in bash_profile and bash_rc.

It's like your own slander, but if you are interested, please try it. And if you're using a useful alias, I'd love to share it.

I also wrote it for study purposes, so there may be incorrect information. I would appreciate it if you could point out that.

alias settings

~/.bash_profile Added the following syntax

if [ -f ~/.myalias ]; then
  source ~/.myalias
fi

~/.myalias

● gist https://gist.github.com/genie-oh/d73a224e7cb3cffab2868182eb79ccad

# show full command & execute 
alias al='_(){ CMD=$(alias | grep "alias $1=" | cut -d = -f 2- | sed "s:^.\(.*\).$:\1:"); ARG=$(echo $@ | sed "s/^$1//"); CMD="${CMD}${ARG}"; echo "execute : ${CMD}"; echo " "; bash -c "${CMD}"; };_'

# docker
alias al-dock='cat ~/.myalias | grep dock | sed "s/=/      \t\= /"'
alias dock='docker'
alias docki='docker images'
alias dockps='docker ps -a'
alias dockrrm='docker run --rm'
alias dockeit='docker exec -it'
alias dockrm='docker rm -f'
alias dockrmi='docker rmi -f'
alias dockrma='docker rm -f $(docker ps -aq)'
alias dockrmia='docker rmi -f $(docker images -aq)'
alias dockins='docker inspect'
alias dockip='docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}"'
alias docklogs='dock logs --tail 50 --follow --timestamps'
alias dockc='docker-compose'
alias dockcb='docker-compose build'
alias dockcu='docker-compose up -d'
alias dockcd='docker-compose down'
alias dockccl='grep container_name docker-compose.yml'

※Description

al-dock View a list of Docker-related aliases

$ al al-dock
execute : cat ~/.myalias | grep dock | sed "s/=/      \t\= /"
 
# docker
alias al-dock           = 'cat ~/.myalias | grep dock | sed "s/=/      \t\= /"'
alias dock              = 'docker'
alias docki             = 'docker images'
alias dockps            = 'docker ps -a'
alias dockrrm           = 'docker run --rm'
alias dockeit           = 'docker exec -it'
alias dockrm            = 'docker rm -f'
alias dockrmi           = 'docker rmi -f'
alias dockrma           = 'docker rm -f $(docker ps -aq)'
alias dockrmia          = 'docker rmi -f $(docker images -aq)'
alias dockins           = 'docker inspect'
alias dockip            = 'docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}"'
alias docklogs          = 'dock logs --tail 50 --follow --timestamps'
alias dockc             = 'docker-compose'
alias dockcb            = 'docker-compose build'
alias dockcu            = 'docker-compose up -d'
alias dockcd            = 'docker-compose down'
alias dockccl           = 'grep container_name docker-compose.yml'

dockc, dockcb, dockcu, dockcd docker-compose related docker-compose build, up, down

alias dockc             = 'docker-compose'
alias dockcb            = 'docker-compose build'
alias dockcd            = 'docker-compose down'
alias dockcu            = 'docker-compose up -d'

dockccl Print a list of container names in docker-compose.yml

alias dockccl           = 'grep container_name docker-compose.yml'
$ al dockccl
execute : grep container_name docker-compose.yml

    container_name: lamp-web
    container_name: lamp-php
...abridgement

docki Output a list of docker images

alias docki             = 'docker images'
$ al docki
execute : docker images

REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
centos                   7                   b5b4d78bc90c        8 weeks ago         203MB
docker-lamp-test_php     latest              e6d67d8f48cf        17 minutes ago      666MB
...abridgement

dockps View docker container list and execution status

alias dockps            = 'docker ps -a'
$ al dockps
execute : docker ps -a

CONTAINER ID        IMAGE                    COMMAND                  CREATED             STATUS                          PORTS                     NAMES
6116324251dd        docker-lamp-test_php     "docker-php-entrypoi…"   17 minutes ago      Up 17 minutes                   0.0.0.0:32769->9000/tcp   lamp-php
...abridgement

dockeit Command execution in interactive & tty mode in a running container docker exec --interective --tty

alias dockeit           = 'docker exec -it'
$ al dockeit lamp-php bash
execute : docker exec -it lamp-php bash

root@37bcdbd02f92:/var/www/html# ls
config  gulpfile.js  home_root  home_sub  nodeapp

dockrrm Exit the container immediately after executing the command in the container Create container ▶ Execute command ▶ Exit container

alias dockrrm           = 'docker run --rm'
$ al dockrrm composer php -v
execute : docker run --rm composer php -v

PHP 7.4.7 (cli) (built: Jun 11 2020 18:58:32) ( NTS )
...abridgement

dockins Check the status of the container

alias dockins           = 'docker inspect'
$ al dockins lamp-php
execute : docker inspect lamp-php

[
    {
        "Id": "6116324251ddffc8090cc605d391f89a951aeb46d32636dd62476a225a894c51",
        "Created": "2020-07-01T13:30:27.11145Z",
...abridgement

dockip Get only IP in container state

alias dockip            = 'docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}"'
$ al dockip lamp-php
execute : docker inspect --format="{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}" lamp-php

172.30.0.5

docklogs Check the container log

alias docklogs          = 'dock logs --tail 50 --follow --timestamps'
$ al docklogs lamp-php
execute : docker logs --tail 50 --follow --timestamps lamp-php

2020-07-01T13:30:28.338589500Z [01-Jul-2020 22:30:28] NOTICE: fpm is running, pid 1
2020-07-01T13:30:28.340324600Z [01-Jul-2020 22:30:28] NOTICE: ready to handle connections

dockrm, dockrmi Delete a specific container or image

alias dockrm            = 'docker rm -f'
alias dockrmi           = 'docker rmi -f'

dockrma, dockrmia Delete all containers or images

alias dockrma           = 'docker rm -f $(docker ps -aq)'
alias dockrmia          = 'docker rmi -f $(docker images -aq)'

Recommended Posts

Docker. Set frequently used commands to alias "with explanation"
Summary of frequently used commands (with petit commentary)
pyenv Frequently used commands
Frequently used tmux commands
Frequently used Linux commands
Frequently used Linux commands
Frequently used linux commands
Frequently used pip commands
Frequently used commands in virtualenv
Design patterns to enjoy with frequently used Java libraries --Builder patterns
Design patterns to enjoy with frequently used Java libraries --Adapter patterns
Design patterns to enjoy with frequently used Java libraries --Strategy patterns
8 Frequently Used Commands in Python Django
Linux Frequently Used Commands [Personal Memo]
[Linux] Frequently used Linux commands (file operation)
Design patterns to enjoy with frequently used Java libraries --Template Method patterns
Frequently used Linux commands (for beginners)
List of frequently used Linux commands
[Anaconda3] Summary of frequently used commands
[Linux] Frequently used Linux commands (folder operation)
Design patterns to enjoy with frequently used Java libraries --Facade pattern
Use Docker Desktop for Windows to start the latest odo with 2 commands
Design patterns to enjoy with frequently used Java libraries --Abstract Factory pattern
[Blender] How to set shape_key with script
[Linux] Review of frequently used basic commands 2
Summary of frequently used commands of django (beginner)
Summary of frequently used commands in matplotlib
Set up a Samba server with Docker
Connect to MySQL with Python within Docker
[Linux] Review of frequently used basic commands
How to install python3 with docker centos
[Python/Django] Summary of frequently used commands (3) <Operation of PostgreSQL>
How to delete log with Docker, not to collect log
[Linux command] A memorandum of frequently used commands
[Python/Django] Summary of frequently used commands (2) <Installing packages>