Code Monkey home page Code Monkey logo

docker_intro's Introduction

Docker

image
Docker is a set of platform as a service (PaaS) products that use OS-level virtualization to deliver software in packages called containers. Containers are isolated from one another and bundle their own software, libraries and configuration files; they can communicate with each other through well-defined channels. Because all of the containers share the services of a single operating system kernel, they use fewer resources than virtual machines.

How to set up Docker (on Windows 10)

  1. Visit https://docs.docker.com/desktop/windows/install/
  2. Make sure WSL 2 backend is selected and download the installer.
  3. Run the installer and restart PC when prompted to.
  4. Docker should start on system startup to finalize installation.
  5. When this error shows: image Click on the link to go to Microsoft Docs page with the latest WSL2 kernel update. Then click on ‘download the latest WSL2 Linux kernel’ link on the page to download ‘wsl_update_x64’ setup file.
  6. Run the wsl_update_x64 file
  7. Verify installation by typing docker version in a command line.
  8. Start docker, go to Settings --> Resources and tick Enable integration with my default WSL distro image

Docker benefits

  1. Introduces the philosophy of Separation of Concerns and ensures Agile Development of software applications in both simple and complex domains.
  2. The standalone ability or independent nature of microservices open doors for following benefits:
  • Reduces complexity by allowing developers to break into small teams, each of which builds/maintains one or more services.
  • Reduces risk by allowing deployment in chunks rather than rebuilding the whole application for every change.
  • Easy maintenance by allowing flexibility to incrementally update/upgrade the technology stack for one or more services, rather than the entire application in a single point in time.
  • In addition to giving you the flexibility to build services in any language, thereby making it language independent, it also allows you to maintain separate data models of each of the given services.
  1. You can build a fully automated deployment mechanism for ensuring individual service deployments, service management and autoscaling of the application.

Microservices architecture

image

Microservices vs monolith architecture

monovsmicro

VM vs Docker

Docker commands

  • docker run image_name
  • docker build -t account_id/image_name/tag
  • docker push image_name
  • docker stop container_id
  • docker rmi image_name
  • docker rmi image_name -f

Naming convention for images

account_id/image_name/tag
vimitre/app/v1
If tag is not provided, it will be 'latest'.

Pull an image from docker hub

  • docker pull image_name
  • Example: docker pull ahskhan/sparta-app-dockerised:v1

Example of using an existing image

  • ghost image
  • docker run -d -p 2368:2368 ghost

Check container state

  • docker ps or docker ps -a

Interact with running container

To open a shell in container:

  • docker exec -it container_id bash
  • If there is an error, run this: alias docker="winpty docker"

To send a command to run in container:

  • docker exec -it container_id bash -c command

Download documentation in a container:

docker run -d -p 4000:4000 docke/docker.github.io

Nginx

docker run -d -p 80:80 nginx

Task: Customise an Nginx image

  1. Create repository on DockerHub: sre_customised_nginx
  2. Create a new index page
  3. Copy the index.html file to the default location of nginx' index page: docker cp index.html 3adb9f0cbb05:/usr/share/nginx/html/
  4. Commit the change: docker commit 3adb9f0cbb05 sre_customised_nginx
  5. Push it to DockerHub: docker push vimitre/sre_customised_nginx
  6. Check if it worked: docker run -d -p 80:80 vimitre/sre_customised_nginx

Build an image

  • Create a Dockerfile:
# Choose image
FROM nginx

LABEL MAINTAINER=vimitre

# Copy local index.html to container
COPY index.html /usr/share/nginx/html/

# port 80
EXPOSE 80

# CMD to launch the nginx web server
CMD ["nginx", "-g", "daemon off;"]
  • Build the image:
    docker build -t vimitre/sre_nginx_test:v1 .
  • Push it:
    docker push vimitre/sre_nginx_test

Create a Micro-Service for the Node-App with Docker

  • Build an image for the app
  • Select node image
  • LABEL
  • COPY dependencies from localhost to container app /default location
  • Copy package.json files
  • RUN npm install
  • RUN npm install express
  • RUN node seeds/seed.js
  • EXPOSE 3000
  • CMD ["node", "app.js"]

Dockerfile (inside app directory):

FROM node

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install -g npm@latest
RUN npm install express

# RUN node seeds/seed.js

COPY . .

EXPOSE 3000

CMD ["node", "app.js"]
  • Run it:
    docker run -d -p 80:3000 vimitre/sre_node_app:v1

To stop all containers: docker rm -f $(docker ps -a -q)

docker history image_name

Docker compose

docker compose up -d docker compose down

Volumes

  • List available volumes: docker volume ls
  • Create volume: docker volume create volume_name
  • Inspect volume: docker inspect volume volume_name
  • Delete volume: docker volume rm sre_viktor

docker_intro's People

Contributors

vimitre avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.