Tuesday, March 1, 2022

EXTRA INFOS: Scratch Docker Images

 


When building Docker containers you define your base image in your Dockerfile. The scratch image is the smallest possible image for docker. Actually, by itself it is empty (in that it doesn't contain any folders or files) and is the starting point for building out images.

This image is most useful in the context of building base images (such as debian and busybox) or super minimal images (that contain only a single binary and whatever it requires, such as hello-world).

While scratch appears in Docker’s repository on the hub, you can’t pull it, run it, or tag any image with the name scratch. Instead, you can refer to it in your Dockerfile. For example, to create a minimal container using scratch:


FROM scratch

COPY hello /

CMD ["/hello"]

EXTRA INFOS: Networking Homework

 


Homework by Raman (JUMP IBM PROGRAM) 1 March 2022:

  1. what is networking between computers?
  2. what is client server networking?
  3. what is CIDR range?
  4. Check an IP exist in that CIDR range.



Answers:

1. what is networking between computers?

A computer network comprises two or more computers that are connected—either by cables (wired) or WiFi (wireless)—with the purpose of transmitting, exchanging, or sharing data and resources. You build a computer network using hardware (e.g., routers, switches, access points, and cables) and software (e.g., operating systems or business applications).

Geographic location often defines a computer network. For example, a LAN (local area network) connects computers in a defined physical space, like an office building, whereas a WAN (wide area network) can connect computers across continents. The internet is the largest example of a WAN, connecting billions of computers worldwide.

types of network:

LAN - usually in a building

You can further define a computer network by the protocols it uses to communicate, the physical arrangement of its components, how it controls traffic, and its purpose.

Computer networks enable communication for every business, entertainment, and research purpose. The internet, online search, email, audio and video sharing, online commerce, live-streaming, and social networks all exist because of computer networks.


2. what is client server networking?

In a client/server network, a central server or group of servers manage resources and deliver services to client devices in the network. The clients in the network communicate with other clients through the server. Unlike the P2P model, clients in a client/server architecture don’t share their resources. This architecture type is sometimes called a tiered model because it's designed with multiple levels or tiers.


3. what is CIDR range?

Use Classless Inter-Domain Routing (CIDR) notation in the format <IPv4_address>/number, such as 10.10.0.0/16. Reserve the last 16 bits (65,536 addresses) of the IPv4 as 0s so that you can use them for various subnet IP addresses(within the same CIDR range) within the same IBM Cloud® VPC, such as 10.10.1.0/24

If you use an IP range outside of the ranges RFC 1918 defines (10.0.0.0/8, 172.16.0.0/12, or 192.168.0.0/16) for a subnet, the instances attached to that subnet might be unable to reach parts of the public internet. If you plan to configure VPCs that use both non-RFC-1918 addresses and also have public connectivity (floating IPs or public gateways), make sure to use a custom route that contains the Delegate-VPC action.








4. 
Check an IP exist in that CIDR range.
What comes after the slash determines the quad notation
Dotted quad notation
The smaller the number after the slash, the more IP addresses that you are allocating. The number after the slash represents the number of leading 1 bits in the subnet's prefix mask.

Docker Compose

 


Docker Compose
it is a microservice approach to create containers and manage containers for orchestration.
docker-compose is a tool for defining and running multi-container Docker applications. With docker-compose, you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Using Compose is basically a three-step process:
1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
2. Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
3. Run docker-compose up and Compose starts and runs your entire app.

Docker Compose commands:

docker-compose up -d

This will create a network, and create the containers as per defined in the docker-compose.yml file

docker-compose down

This will stop and remove the containers then it will remove the network. The containers stopped and removed are as of defined in the docker-compose.yml file.

docker-compose scale db=2

If for exam[le in the docker-compose.yml file, you specified a db container, using the scale command, it will create for you 2 db containers.


Install Docker compose file

sudo curl -L "https://github.com/docker/compose/releases/download/1.23.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose

chmod +x /usr/local/bin/docker-compose

docker-compose --version

Example 1:


version: '3.3' 
services: 
         db: 
                 image: mysql:5.7 
                 volumes: 
                   - db_data:/var/lib/mysql 
                 restart: always 
                 environment: 
                     MYSQL_ROOT_PASSWORD: somewordpress 
                     MYSQL_DATABASE: wordpress 
                     MYSQL_USER: wordpress 
                     MYSQL_PASSWORD: wordpress 

         wordpress: 
             depends_on: 
                     - db 
                         image: wordpress:latest 
                         ports:
                          - "80:80" 
                         restart: always 
                         environment: 
                             WORDPRESS_DB_HOST: db:3306 
                             WORDPRESS_DB_USER: wordpress 
                             WORDPRESS_DB_PASSWORD: wordpress 
                             WORDPRESS_DB_NAME: wordpress 
                        volumes: 
                          db_data: {}


docker-compose up -d
docker-compose down


Example 2
version: '3.3' 
services: 
     db: 
         image: ramansharma95/mysql 
     webapp: 
         image: ramansharma95/webapp 
         ports: 
             - "80:80"

Run the following command in mysql container:

docker exec -it <<containerid>> bash 
mysql -uroot -pwhizlabs
create database company;
use company;
create table employee ( name varchar(30), mobile varchar(30));
select * from employee;

Fluentd

Open-source log data collector > why logs? - for compliance (auditing, company, business) - for security (transparency, monitoring, admin...