Ramesh Ponnusamy
3 min readJan 25, 2019

Docker Basics

Hi folks, Now I’m going to share my experience on working with docker. Docker is an awesome technology which is used to make our development process easy and we can move it from one machine to another. Following things are what I feel when I’m using the docker: a helpful tool for packing, shipping, and running applications within “containers.”

Containers and VM’s are similar in their goals: to isolate an application and its dependencies into a self-contained unit which can run anywhere.

Moreover, containers and VMs remove the need for physical hardware, allowing more efficient use of computing resources, both in terms of energy consumption and cost effectiveness.

Let’s take a closer look.

  1. Docker is easy to set up our server and easy to maintain.
  2. Also Assign a IP for containers by using subnet(Network).
docker network create --subnet=172.18.0.0/16 dbmc-net

3. We run multiple servers in single machine because every server runs in individual containers, so there is no problem for dependency

Server Container:
docker run -it -h dbmc-appserver-node --ip 172.18.0.6 --net dbmc-net -p 0.0.0.0:80:9000 -d --name appserver ubuntu
Database Container:
docker run -it -h dbmc-mysql-node --ip 172.18.0.5 -p 0.0.0.0:3306:3306 --net dbmc-net -v /root/docker-data/mariadb:/var/lib/mysql --name database -e MYSQL_ROOT_PASSWORD=password -d ubuntu

4. Add IP for containers thats already created.

Location — sudo vim /etc/hosts Note — in Landing machine not in docker

Add the server names and their appropriate IP’s that you want to assign

172.18.0.5 dbmc-mysql-node172.18.0.2 dbmc-appserver-node

We need to grant permission in mysql container to expose the data from appserver container.

GRANT ALL ON * . * TO root@'172.18.0.2' IDENTIFIED BY 'password'; 

Database bind address should be 0.0.0.0 Then it can be accessed globally.

Note: In database Conatainer:
Location: vim /etc/mysql/my.cnf
change the bind address to 0.0.0.0 from 127.0.0.1

Assign system memory(RAM) to containers in a distributed way such that it does not affect the overall performance.

Memory failure can crash a docker and its host completely

docker run -it -h dbmc-appserver-node --ip 172.18.0.6 --net dbmc-net  -p 8081:80 -m 300M -d --name appserver ubuntu

One of the failsafe feature in docker is it prevents our system from crashing while testing a random package/driver. If something suspicious happens, we can drop the container and move on with a new one.

sharing is caring!

The major plus point of docker is sharing that saves most of our time. Save the container as .tar and restore it on any machine.

Containers allow a developer to package up an application with all of the parts it needs, such as libraries and other dependencies, and ship it all out as one package.

Say Bye bye to “It works on my machine, I don’t know why it won’t work on yours.” This is what Docker is designed to prevent.

Transfer the container from one place into another like Hanuman transfer the mountain

To commit container

First Commit your docker container:
docker commit “appserver” appserver

To Save the container as image

Save as .tar file in your host system:
docker save appserver > appserver.tar

Docker images are executable packages that include everything needed to run an application — the code, a runtime, libraries, environment variables, and configuration files.

Docker containers are a runtime instance of an image — what the image becomes in memory when executed.

Every single Docker container begins as a pure Linux machine that knows nothing. It has the Only Image’s properties such as code ,dependencies, libraries,etc

To Load the container as image

Copy the .tar file into another host machine

Load the .tar file:
docker load < appserver.tar

After loading the .tar file its now a image that has appserver all properties and then you can create a container from appserver image.

Note appserver in bold is now Image:
docker run -it -h dbmc-appserver-node --ip 172.18.0.6 --net dbmc-net -p 8081:80 -m 300M -d --name appserver appserver

To Copy From Docker to Local

docker cp <containerId>:/file/path/within/container /host/path/target

Conclusion

If you are working in development area , Blindly you can go with docker It helps you to make your progress in flexible way.

Ramesh Ponnusamy
Ramesh Ponnusamy

Written by Ramesh Ponnusamy

Data-Architect, SQL Master,Python ,Django, Flask dev, AI prompting, Linked-in: https://www.linkedin.com/in/ramesh-ponnusamy/ mail : ramramesh1374@gmail.com

No responses yet