Hello, it’s been two months since last update. Anyway the August month I was pretty busy, to be honest, I was involved in a old project of mine that I had to revist, in order to get more productive and flexibility in developing the application I chose to use docker. So this post is going to be about docker.

Status Update:The month of August also had something interesting in it, which is my birthday. There was a plan to go a special temple so I took some leave from office, during that time another holiday was also just around the corner, so on the whole I had about 5 days of stay in my house, which is a lot considering I only have a two or three days leave if I had leave my office. This was the first time after a year that I have been staying in home for a long time. During that time I spent some minimal time developing and I found out that I had so much productivity in home then in my chennai room or my office and I was learning new things, so that is that.


Will reference everything with the assumption you are on the linux platform too, it’ll be only slightly different on windows.


Intro to docker

installation

I recommend installation with the prebuilt packages from the docker link instead of your flavour’s package (debian[ubunut..], arch..).


# use the following path while navigating through to get the download links.

pool/dist/package

(or)

if you insist on installing with apt.


# installation with apt / apt-get
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg-agent \
    software-properties-common
gpg key:
 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

check fingerprint:
sudo apt-key fingerprint 0EBFCD88

pub   rsa4096 2017-02-22 [SCEA]
      9DC8 5822 9FC7 DD38 854A  E2D8 8D81 803C 0EBF CD88
uid           [ unknown] Docker Release (CE deb) <docker@docker.com>
sub   rsa4096 2017-02-22 [S]

#choosing stable release for docker:
sudo add-apt-repository \
   "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
   $(lsb_release -cs) \
   stable"

#installing latest docker from ubuntu.
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io

#deb is even simpler in my openion (example for debian): 
sudo dpkg -i /path/to/package.deb 

basics

the following are true for linux based distros

To put it simple terms Docker is like a virtualMachine except it’s not resource hungry.

To not put in simple terms Docker shares the same kernel as the host, while VirtualMachine rewrites low-level instructions & executes them on the fly.


image

images are like iso images burnt to a cd/usb ready to be installed, things you can do with it, * use prebuilt images from market, (both official and user created) * build an image with customisations on top of an official image form market * publish the images you are using/ publish images that you built


container

Image u have a fresh HardDisk, you installed a OS(operating system) of your liking in it, what do you have left in it? Free space after the o-files, which u can use to store anything, what can you install on the os? basically any software, so next time if you take that particular hardDisk will you get, basically above right? This is what a container is, replace HardDisk with container and os with prebuilt/customImage. you can attach external HardDrive to it, which in our case is volume, …etc


basic commands


#list local images/containers
docker image ls

#only running containers
docker container ls 

#list all (even turned off containers)
docker contaienr ls -a


custom image creation section

some commands to help you(addressig myslef), for custom images.


# dockerfile
FROM <imagename>:<tagfortheimage>
COPY <src> <dest>
WORKDIR further interaction will start from this directory.
EXPOSE port to be exposed.
# installed additioal/required programs from below commands
RUN commands to run 
CMD commands to run 

build the image, filename for the file should be ‘Dockerfile’


docker-build -f PathToFile -t nameOfTheBuildImage
#ex:
docker build -t phpserver:0.0.2 phpServer/

docker image ls phpserver

REPOSITORY          TAG                 IMAGE ID            CREATED              SIZE
phpserver           0.0.2               5f7b4c7374b5        About a minute ago   416MB

#another way of representing, httpd/somefeature:tagHere, httpd/somefeature (tag assumed as latest here), user/httpd-imageName:taghere

running a image which you built locally or from the official image,


docker-run -d run-container-in-background -v specify-volume / --mount --mount='-type=bind,src=path_here,dst=path_here' (path must be absolute --name='' -p [] (port) -p [] (port)

ex:
docker run -d -p 80:80  --mount='src=//bluepie.in/home/path/to/folder/,dst=/var/www/html/,type=bind' --name phpserver  phpserver:0.0.2

docker ps 

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                NAMES
5f7b4c7374b5        phpserver:0.0.2     "docker-php-entrypoi…"   10 seconds ago      Up 9 seconds        0.0.0.0:80->80/tcp   phpserver

after starting the container, some commands to help you,



docker-container start name
docker-container stop name
docker-container restart name
docker-container stat 
docker-container inspect name
docker-container ls -a 
docker-container la

to interact with running containers


#run single instance command
docker-exec -i image command-here params-if-command-has-it
#ex: install php inside a conainer and use it like binary like this
docker run \
    --rm \
    -i \
    --network=host \
    -v "$HOME":"$HOME":ro \
    -u $(id -u) \
    -w "$PWD" \
    php:7.3-alpine \
    php "$@"

#run interactive shell command
docker-exec -it image 


docker compose

wana start a bunch of container’s each serving its own purpose, for eg: one container for running server, another for databse, another for running waf, another for running microService ?

install docker-compose, downlaod the docker-compose binary and include it in your environment variable, and build a docker-compose.yml for it.

bye, see ya soon, sorry for missing out last month