Docker

1. What is docker?

A platform for building, running, and shipping applications.

Problem: Code work in your laptop -> didn't work somewhere

Reasons:

  • One or more files missing

  • Software version mismatch

  • Difference configuration settings

With docker you can do it.

  • Package Your machine

  • Remove machine and code in 1 line code

docker-compose up
docker-compose down

Consistency

2. Virtual Machines vs Containers

Container : An isolated environment for running an application.

Virtual Machines: An abstraction of a machine. You can run many machine like window, linux in mac devices by using a tool called hypervisor.

Hypervisor

  • VirtualBox

  • VMware

  • Hyper-V (window only)

Problems

  • Each VM needs a full-blown OS

  • Slow to start

  • Resource intensive

Containers

  • Allow running multiple apps in isolation

  • Are lightweight

  • Use OS of the host

  • Start quickly

  • Need less hardware resources

You want to use container to contribute your package to users.

3. Architecture of Docker

  • Client - Server Architecture

Kernel is machine of the car.

4. Installing Docker

  • Installing docker Hub from https://docs.docker.com

    • Requirements

    • Error W2L installation incomplete -> Download Linux kernel

docker version  -> Client + Server

5. Development Workflow

Application (Docker file) --> Image --> Container

Image

  • A cut-down OS

  • A runtime environment (eg Node)

  • Application files

  • Third-party libraries

  • Environment variables

Dev -> Registry -> Test

6. Docker in Action

Code:

mkdir hello-docker

cd hello-docker

Edit in VS code

Create Dockerfile -> install extension

FROM linux or node // Go to hub.docker.com search node Image
FROM node:aplpine
COPY . /app
WORKDIR /app
CMD node /app/app.js 


docker build -t hello-docker . //Store Image
docker images or docker image ls
docker run hello-docker



Play with docker

  • Login docker

  • Add new instance

  • node -> not found

  • docker version

  • docker pull codewithmosh/hello-docker

  • docker image ls

  • docker run hello-docker

7. The linux command line

Because Docker is built on basic Linux concepts

8. Linux distributions

Open source

Distros

  • Ubuntu

  • Debian

  • Alpine

  • Fedora

  • CentOS

--> Same command

9. Running Linux

hub.docker.com --> search ubuntu -> download image

docker pull ubuntu // docker run ubuntu

docker ps - a

docker run -it ubuntu

Shell prompt :

echo $0 // location of program
echo hello / whoami
history

10. Managing your packages

Package Managers

  • npm

  • yaml

  • pip ...

apt //advance package tools
apt-get

//Install nano
nano // Package
apt install nano
apt list
apt update nano
apt list
apt install nano
nano
apt remove nano


//Install python



11. Linux File system

Tree systems

  • /

    • bin

    • root

    • home

    • etc //editable text configuration

12. Navigating the File System

pwd //
ls //list
ls -1
ls -l
cd etc/a
cd etc/apt
cd ../../ //out
ls /bin


cd ~ 





13. Manipulating Files and Directories

cd ~
mkdir test
ls
mv test docker
ls
cd docker/
touch hello.txt
touch file1.txt file2.txt file3.txt
ls
ls -1
mv hello.txt hello-docker.txt
mv hello.txt /etc
rm file1.txt file2.txt file3.txt
rm file*

rm -r docker //remove directories



14. Viewing and Editing file

//Editing
nano // text editor for linux
apt install nano
nano file1.txt


//Viewing
cat file1.txt //viewing file
more file1.txt

//less
apt install less
less 

//head
head -n 5 file1.text

//tail 
tail -n 5 file1.txt

15. Redirection

cat file1.txt > file2.txt




Last updated

Was this helpful?