- Codebase/Revision Control
- Dependencies
- Config
- Backing Services
- CI/CD
- Processes
- Port Binding
- Concurrency
- Disposability
- Development/Production Parity
- Logs
- Admin Processes
Docker commands
>docker version
>docker info
Searches images in docker registry.
docker search <Image Name>
>docker search ubuntu
List all the downloaded images
>docker images
>docker ps –a
-a – show all
-l – show last
Pulls the image if it is not available locally. It runs automatically by docker run.
>docker pull <Image name>
Docker run starts the container by giving the image name a process to run in that container. The container stops when the main process stops. It automatically pulls the image.
>docker run –ti <image>:[<version/latest>] <program to run>
-ti – terminal interactive
-d – detach – will run in the background
-c – command
-p – port. eg. –p 1234:3456 Expose port 1234 on the inside of the container to the outside of container as port 3456.
docker run –p <outside-port>:<inside-port>/protocol(tcp/udp)
-v – volume
docker run –v <path in host>:<inside the container path>
>docker run –ti –v /home/docker/example:/shared-folder ubuntu bash
--name – name of the container
--memory – maximum allowed memory
--cpu-shares – relative to other containers
--cpu-quota – limit it
--link <Name of container> – for communication between two containers. It automatically assigns a hostname. Link can break when containers restart.
--net==<Network name>
--volumes-from <Name of the container that we want to use the volume> – To share data/file between containers.
>docker commit <id of the container>
Tagging gives images names
>docker tag <id received from commit> <Image/Tag name>
or
>docker commit <Name of the container> <Image/Tag name>
Creates an image for the docker file
>docker build –t <Name of tag> .
The (.) shows the docker file in here. Otherwise need to pass the path of docker file.
Upload a tagged image to docker hub
>docker push <Tag name>
>docker attach <Container name>
>docker exec
Starts another process in an existing container.
Docker logs keep the output of the container.
>docker logs <Container name or ID>
>docker kill <Container name/ID>
>docker rm <Container name/ID>
>docker network create <Network name>
>docker rmi <Image name/Image ID>:<Tag>
Login in to docker hub
Modules:
Module help us with encapsulation by exposing from a given file the pieces we want to be access publically. An export statement will be used for that.
export {
show: someFunc()
}
Then an import statement is used to import that piece:
import { show } from './my-file.js'
New features in ES6 are:
let, const and Block Scoping:
let
let statement allows to declare variables that are limited in scope to the block, statement or expression on which it is used.
Arrow Functions =>
Arrow functions are anonymous functions with shorter syntax than a function.
Arrow function without any arguments.
var geEmployee = () => console.log(‘Employee Name’);
Default Function Parameters:
var getEmployee = function(id = 101){
console.log(id)
};
getEmployee();
Thanks,
Bimal
A list of commands are defined to build Docker image.
The first statement/command in the docker file which tells which image to download and start from.
Describes the author of the docker file.
MAINTAINER <First name> <Last name> <email address>
Run a command, wait for the result and then saves the result.
RUN echo hello docker
Adds local files, contents of a tar archives and works with urls.
Helps to set environment variables, both during the build and when running the result.
ENV artifactId=com.org.artifactId
Specifies the start of the command to run
Specifies the whole command to run
Maps a port into the container
EXPOSE 8080
Defines shared or ephemeral volumes.
VOLUME [“/host/path/” “/container/path/”]
VOLUME [“/shared-data”]
Sets the directory the container starts in. It is similar to use ‘cd’ after start.
WORKDIR /install/
Sets which user the container will run as.
USER bimal
USER 1000
TypeScript is a superset of JavaScript. When TypeScript is compiled, it transpiled to JavaScript.
Features:
Static Typing:
let name: string
let age: number
let dob: data
Interfaces:
interface IEmp {
name: string
age?: number //Optional property
dob: date
}let myEmp: IEmp
Class Properties:
class Employee {
name: string}
dob: date
constructor (name){
this.name = name
}
Access Modifier:
Class members are public by default in both ES6 and TypeScript.
class Employee {
private name: string}
private getSalary() {
console.log(‘Salary of ’ + this.name + ‘ is $5000.00‘)
}
Custom matchers, provided by the behavior-driven development framework Jasmine, is a great feature for testing JavaScript code. Custom Matchers helps to group multiple catch checking which makes the test cases clean and self explanatory.
Let’s look at an example that I tried recently
Here is a Calculator.js file:
1: var Calculator = function () { };
2:
3: Calculator.prototype.add = function (a, b) {
4: return a + b;
5: };
6:
7: Calculator.prototype.divide = function (a, b) {
8: return a / b;
9: };
One of the test scenarios that I would like to try is to check whether the result of the method is in a particular range. The test method will look like this with existing matchers.
1: describe('Calculator', function () {
2: var calc;
3:
4: beforeEach(function () {
5: calc = new Calculator();
6: });
7:
8: it('should be able to add 1 and 1', function () {
9: expect(calc.add(1, 1)).toBe(2);
10: });
11:
12: it('should be able to divide 6 by 2', function () {
13: expect(calc.divide(6, 2)).toBe(3);
14: })
15:
16: it('should be able to divide a rational number', function () {
17: expect(calc.divide(1, 3)).toBeLessThan(0.34);
18: expect(calc.divide(1, 3)).toBeGreaterThan(0.3);
19: })
20: });
But you can replace the existing matchers with a custom matcher like this.
1: describe('Calculator', function () {
2: var calc;
3:
4: beforeEach(function () {
5: calc = new Calculator();
6:
7: jasmine.addMatchers({
8: toBeBetween: function (util, customEqualityTesters) {
9: return {
10: compare: function (actual, a, b) {
11: var result = {};
12: result.pass = actual >= a && actual <= b;
13: return result;
14: }
15: }
16: }
17: });
18: });
19:
20: it('should be able to add 1 and 1', function () {
21: expect(calc.add(1, 1)).toBe(2);
22: });
23:
24: it('should be able to divide 6 by 2', function () {
25: expect(calc.divide(6, 2)).toBe(3);
26: })
27:
28: it('should be able to divide a rational number', function () {
29: expect(calc.divide(1, 3)).toBeBetween(0.3, 0.34);
30: })
31: });
You can reuse custom matchers to make the test cases clear and more simple.
What are some scenarios that you use custom matchers?