Showing posts with label Docker. Show all posts
Showing posts with label Docker. Show all posts

Friday, 9 August 2019

Setup Aliases for Docker


While working on Docker in day to day work I realized that it's little difficult to remember each command which is required to work on docker container so I have started to build my docker alias command list.

I have tried to use minimum no of characters in alias command with a hint of command and every alias start with letter 'd' so that it can be easily maintained when managing multiple alias for different tools.

Create a bashrc file if not exist or append below alias list in you bashrc and set this in your user profile so that when you login on terminal, all the aliases will be available to use.




########################################################
# Docker Alias
########################################################
alias dc='docker ps'
alias dcommit='docker commit'
alias dcopy='docker cp'
alias dcs='docker ps -as'
alias dhist='_() { docker history "$1" --format "{{.ID}}: {{.CreatedBy}}" --no-trunc };_'
alias di='docker images'
alias dinfo='docker info'
alias dlog='docker logs --follow'
alias dlogin='_(){ docker exec -it "$1" /bin/bash ;};_'
alias dloginu='_(){ docker exec -it -u "$1" "$2" /bin/bash ;};_'
alias dlogn='_(){ docker logs -f `docker ps | grep $1 | awk "{print $1}"` ;};_'
alias dlogt='docker logs --tail 100'
alias dp='docker system prune'
alias dpush='_(){ docker push "$1" ;};_'
alias drmac='docker rm `docker ps -a -q`'
alias drmc='_(){ docker rm "$@" ;};_'
alias drmcc='docker rm $(docker ps -qa --no-trunc --filter "status=created")'
alias drmdc='docker rm $(docker ps -qa --no-trunc --filter "status=exited")'
alias drmdi='docker rmi $(docker images --filter "dangling=true" -q --no-trunc)'
alias drmdn='docker network rm'
alias drmdv='docker volume rm $(docker volume ls -qf dangling=true)'
alias drmi='_(){ docker rmi "$@" ;};_'
alias drmv='docker rm volume'
alias drun='_(){ docker run -d --name "$1" -it --detach "$1" /bin/bash; };_'
alias dstats='docker stats'
alias dstop='_(){ docker stop "$@" ;};_'
alias dtag='_(){ docker tag "$1" "$2";};_'
alias dvol='docker volume ls'
alias dvoli='docker volume inspect'
alias dclean=' \
docker ps --no-trunc -aqf "status=exited" | xargs docker rm ; \
docker images --no-trunc -aqf "dangling=true" | xargs docker rmi ; \
docker volume ls -qf "dangling=true" | xargs docker volume rm'




Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Telegram Group     


Tuesday, 6 August 2019

Setup HTTP/S Proxy for Docker


When working with Docker behind the Proxy firewall, docker is unable to communicate to public docker repo (dockerhub) to download or install any dependency for your docker scripts. This you can resolve by altering or creating few config files for docker. Let's see How --

1. In command line:

Use below environment variable in docker command as argument to enable proxy for it

# In Command Line:
--env HTTP_PROXY="http://<user>:<password>@<proxy_server>:<port>"
--env HTTPS_PROXY="http://<user>:<password>@<proxy_server>:<port>"
--env ALL_PROXY="http://<user>:<password>@<proxy_server>:<port>"

 

2. In Docker File:

You can add proxy setting in your docker file if don't have access to change at system level. Just add below line in your docker script.

# In DockerFile
ENV HTTP_PROXY "http://<user>:<password>@<proxy_server>:<port>"
ENV HTTPS_PROXY "http://<user>:<password>@<proxy_server>:<port>"
ENV ALL_PROXY "http://<user>:<password>@<proxy_server>:<port>"



3. Using config.json (Client level) file:

Or you can create user level config file for docker environment if not exist. These settings will be available to your docker script by default until override by other means. 

# Create/Edit ~/.docker/config.json file (All below json in this file, create file if not exists)
 

{
 "proxies":
 {
   "default":
   {
     "httpProxy": "http://<user>:<password>@<proxy_server>:<port>",
     "httpsProxy": "http://<user>:<password>@<proxy_server>:<port>",
     "allProxy": "http://<user>:<password>@<proxy_server>:<port>"
   }
 }
}



4. Using docker system level config change (Docker Server level):

You can change the docker server level proxy change to use it as below: 


# Altering Docker Syetem File (you have to be root user for this)
sudo mkdir -p /etc/systemd/system/docker.service.d
sudo vi /etc/systemd/system/docker.service.d/http-proxy.conf
 
#(add below content to this file )
[Service]
Environment="HTTP_PROXY=http://<user>:<password>@<proxy_server>:<port>"
Environment="HTTPS_PROXY=http://<user>:<password>@<proxy_server>:<port>"
Environment="ALL_PROXY=http://<user>:<password>@<proxy_server>:<port>"

# now run below command to restart the docker daemon
sudo systemctl daemon-reload
sudo systemctl restart docker

# verify
sudo systemctl show --property=Environment docker





Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Telegram Group     


Monday, 3 June 2019

Containerization - What & Why ??


Containerization, always a word which describe to hold something, literally taken from the world of freight transportation which allows to put lot of different product/item into one box and move around the world without worries of damages. Quite a definition :) Isn't it ?
                 In simple word, or I say in IT term, Containerization is a process or a way which allows user to have a sandbox environment with required software specific to versions which you can flush whenever you are done with it and re-instantiate it when needed.

Now questions comes then what is the difference between a Virtual Machine and Container which we are going to discuss next.

In last decade, Virtual Machines (VM) allow IT giants/users to have one physical machine and host different application and its variants in VMs which shares the resources from host machine. But this comes with a small price, the bottleneck of resources shared. Your physical machine limit to host VMs is totally depends on its resources such as storage, processing power or memory cause VM requires these as contains the guest os and application with its dependencies. Guest OS itself eats lots of host storage & memory and required to be patched on timely manner to support your application.

VM stack is somewhat look like below -

https://www.datagenx.net/2019/02/lets-learn-git-pull-specific-folder.html

Containerization has removed guest OS dependency and uses Host machine and OS which substantially reduce the size of container as well as resources consumption which brings lot more pros over virtual machine. Containerization stack is as below -

https://www.datagenx.net/2019/02/mongodb-index-in-python-simple-index.html
In next post, we will discuss about pros and cons of VM and Containerization.




Like the below page to get the update  
Facebook Page      Facebook Group      Twitter Feed      Google+ Feed      Telegram Group