Knowledge Transfer

Ethickfox kb page with all notes


Project maintained by ethickfox Hosted on GitHub Pages — Theme by mattgraham

==Docker== is a technology that allows you to build, run, test, and deploy distributed applications. It uses operating-system-level virtualization to deliver software in packages called containers.

82.png


Docker Entities

Image

It is a template for environment creation. It has everything your app needs: OS, Software, Code. And might be treated like Snapshot.


Container

Container is a running instance of image

graph LR
  A(IMAGE)-->|RUN| CONTAINER

These containers are isolated from each other and bundle their own tools, libraries, and configuration files. They can communicate with each other through well-defined channels. All containers are run by a single operating system kernel, and therefore use few resources.

Images can be created by either using a 
Dockerfile (which contains all the necessary instructions for creating an image) or by using Docker commit, which takes an existing container and creates an image from it.


Ports

Through the port we can communicate with container.


Volumes

Volume creating - it is the way, how we can share files between host and container / between containers.

docker volume create --name volume-data - create our volume

docker run -d -v volume-data:/data --name nginx-test nginx:latest - mount in the container /data folder.


Dockerfile

Dockerfile it is an instruction how to build our container properly.

ˇ

\#each line creates new layer, each layer have their cache
FROM node:latest
# Open or create dir where you will work
WORKDIR /app
# All further steps will be rerun(cache not used) if there are any changes in this file
ADD package*.json ./
# so all dependencies will be cached and not installed again if package.json not changed
RUN npm install
ADD . .
CMD npm start
FROM adoptopenjdk/openjdk11:jdk-11.0.11_9-alpine-slim
EXPOSE 8092
ARG JAR_FILE=build/libs/PostService-0.0.1-SNAPSHOT.jar
COPY ${JAR_FILE} /app.jar
ENTRYPOINT ["java", "-jar", "app.jar"]

Tags

Tagging allows us to control image version and avoid breaking changes.

alpine images are very lightweight


Docker Registries


Commands

docker attach Attach local standard input, output, and error streams to a running container
docker build Build an image from a Dockerfile
docker builder Manage builds
docker checkpoint Manage checkpoints
docker commit Create a new image from a container’s changes
docker config Manage Docker configs
docker container Manage containers
docker context Manage contexts
docker cp Copy files/folders between a container and the local filesystem
docker create Create a new container
docker diff Inspect changes to files or directories on a container’s filesystem
docker events Get real time events from the server
docker exec Run a command in a running container(-it for interaction)
docker export Export a container’s filesystem as a tar archive
docker history Show the history of an image
docker image Manage images
docker images List images
docker import Import the contents from a tarball to create a filesystem image
docker info Display system-wide information
docker inspect Return low-level information on Docker objects
docker kill Kill one or more running containers
docker load Load an image from a tar archive or STDIN
docker login Log in to a Docker registry
docker logout Log out from a Docker registry
docker logs Fetch the logs of a container
docker manifest Manage Docker image manifests and manifest lists
docker network Manage networks
docker node Manage Swarm nodes
docker pause Pause all processes within one or more containers
docker plugin Manage plugins
docker port List port mappings or a specific mapping for the container
docker ps List containers
docker pull Pull an image or a repository from a registry
docker push Push an image or a repository to a registry
docker rename Rename a container
docker restart Restart one or more containers
docker rm Remove one or more containers
docker rmi Remove one or more images
docker run Create and run a new container from an image
docker save Save one or more images to a tar archive (streamed to STDOUT by default)
docker search Search the Docker Hub for images
docker secret Manage Docker secrets
docker service Manage services
docker stack Manage Docker stacks
docker start Start one or more stopped containers
docker stats Display a live stream of container(s) resource usage statistics
docker stop Stop one or more running containers
docker swarm Manage Swarm
docker system Manage Docker
docker tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE
docker top Display the running processes of a container
docker trust Manage trust on Docker images
docker unpause Unpause all processes within one or more containers
docker update Update configuration of one or more containers
docker volume Manage volumes
docker wait Block until one or more containers stop, then print their exit codes

Docker Compose

version: '3.8'
services:
  redis:
    image: redis:6.2-alpine
    restart: always
    ports:
      - '6379:6379'
      - '8001:8001'
    command: redis-server --save 20 1 --loglevel warning --requirepass eYVX7EwVmmxKPCDmwMtyKVge8oLd2t81
    volumes: 
      - redis:/data
volumes:
  redis:
    driver: './redis'