Container and Docker

Benefits of Container

Lightweight

– dont include a guiest OS

– spin up quivkly and scale horizontaly

Portable and platform independent

Support modern development and architecture

Improve utilization

  • Scale each component individually

Containers VS VM

Image 01

 

Use cases for containers

  • Microservices
    • Loosely coupled and independently deployable services
  • DevOps
    • Build, ship and run software
  • Hybrid, multi cloud
    • Run consistently across environments
  • Application modernizing and migration

 

Docker & CLI

img 01

Common docker commands:

build ( create container image , requires Dockerfile, Tags, or names )

tag ( Names images, Doesn’t overwrite existing image, Creates a new tag)

images ( lists all images , their repos and tags, and ther size)

run ( runs a container, suited for testing an images that has been build)

push | pull ( Stores images in and retrieves images from remote locations)

 

Docker is also a Container runtime

 

 

Docker instructions

img

 

 

Container Registsries

Whats is a container registry

  • Storage and distribution of named container images
  • public or private
  • hosted or self-hosted

Image naming

  • hostname/repository:tag

Example: docker.io/ubuntu:18.04 || docker pull ubuntu:18.04

 

 

Running Containers

FROM node:9.4.0-alpine
COPY app.js .
COPY package.json .
RUN npm install &&\
apk update &&\
apk upgrade
CMD node app.js

docker build -t my-app:v1 .

  • -t – Tag option – specify the name for the image
  • repository my-app v – v1
  • period at the end ( shorthand for the current dir )

docker tag my-app:v1 second-app:v1

Now that we have an images we can run it :

docker run my-app:v1

lets push the image to the registry so we can distribute it and use later

docker push my-app:v1

 

Was this article helpful?

Related Articles

Leave A Comment?