The instance

BusyBox is a compact toolkit that incorporates more than a hundred of the most commonly used Linux commands and tools (cat, echo, grep, mount, Telnet, ping, ifconfig, etc.) – the rm command lets you automatically destroy a container when you exit it for easy testing

docker run –name box1 -it –rm busybox sh

Docker constructs ES and panel management respectively

Segmentfault.com/a/119000002…

Docker-compose builds es cluster

Segmentfault.com/a/119000001…

Kubernetes use

Kubectl create -f test.yaml create pod

Kubectl get Pods can query the current pod list

Kubectl get Po –show-labels query all pods and show labels

Kubectl label Po kubia-manual creation_method=manual Modifies the Pod label

Kubectl label Po kubia-manual-v2 env=debug –overwrite No specified label

Kubectl logs kubia-manual-c kubia Displays application logs

Kubectl get Po kubia-manual-o yaml Queries the Pod description file

Kubectl delete Po –all delete all pods

Kubectl port-forward kubia-manual 8888:8080 Forward Pod

Pod screening

kubectl get po -l creation_method=manual

kubectl get po -l creation_method=manual,env=debug

Use labels and selectors to constrain POD scheduling

kubectl get nodes

kubectl label node minikube gpu=true

kubectl get nodes -l gpu=true

Pod annotations

kubectl annotate pod kubia-manual mycompany.com/someannotation=”foo bar” pod/kubia-manual annotated

Find the namespace

kubectl get ns

kubectl get po –namespace default

Stop and remove the pod

kubectl delete po kubia-gpu

Kubectl delete Po -l creation_method=manual Delete pod using label selector

Kubectl delete ns custom-namespace deletes pod by deleting the entire namespace

Kubectl delete Po –all delete all pods

kubectl delete all –all


Install python

Yum install dl.fedoraproject.org/pub/epel/ep…

Install python3

yum install python3

Install the PIP

curl bootstrap.pypa.io/get-pip.py -o get-pip.py

python3 get-pip.py


Common docker container commands

Docker for MAC install Kubernetes

Github.com/AliyunConta…

Docker Aliyun Accelerator help.aliyun.com/document_de…

One-click installation of docker scripts

curl -sSL get.daocloud.io/docker | sh

Suspension of the container

docker stop

Open the container

docker start

View open containers

docke ps

View all containers

docker ps -a

View the container that was last started

docker ps -l

Docker run -p 80:80 –name webserve-ti -d ubuntu /bin/bash Uppercase -p Can map ports in containers to hosts randomly. –network Smallsha-net Containers can communicate with each other

Enter the container for operation

docker exec -ti webserve /bin/bash

View the container’s mapped port

Docker port Container ID

Container ID View container logs

docker logs -f

View the processes in the container

Docker Top Container ID

View container configuration and environment frequently used

Docker inspect Container Id

Docker rm Container ID Remove the container but the container must be in the stop state docker rm -f Container ID

Docker commit -m=” Commit description “-a=” who committed” Container ID Image copy name Package the currently configured container into an image

Common docker image commands

Docker pull mirror

Docker run mirror

Docker RMI delete image

Build the image label for the container

Docker tag Container ID SmallSHA /centos:dev

Docker container interconnection

Docker network ls View the Docker network

Docker network create -d bridge Smallsha-net Creates a DCOker network bridge

Bridge overlay network

Docker Log in to the Docker Hub

docker login

Docker Tag Mirroring SmallSHA/mirroring

Go to your own DockerHub

Docker push smalsha/ mirroring

Suspend all containers

docker stop $(docker ps -q)

Delete all containers

docker rm -f $(docker ps -aq)

Deleting all Mirrors

docker rmi $(docker images -q)

Build kong

1 Docker network create kong-net create a separate network environment 2 docker run -d --name kong-database \ --network=kong-net \ -p 5432:5432 \ -e"POSTGRES_USER=kong" \
  -e "POSTGRES_DB=kong" \
 -e "POSTGRES_HOST_AUTH_METHOD=trust"Docker run --rm --network=kong-net \ -e"KONG_DATABASE=postgres" \
     -e "KONG_PG_HOST=kong-database"\ kong:latest Kong migrations bootstrap Using temporary Kong containers 4 Docker run -d --name kong --network=kong-net -e"KONG_DATABASE=postgres" \
     -e "KONG_PG_HOST=kong-database" \
     -e "KONG_CASSANDRA_CONTACT_POINTS=kong-database" \
     -e "KONG_PROXY_ACCESS_LOG=/dev/stdout" \
     -e "KONG_ADMIN_ACCESS_LOG=/dev/stdout" \
     -e "KONG_PROXY_ERROR_LOG=/dev/stderr" \
     -e "KONG_ADMIN_ERROR_LOG=/dev/stderr" \
     -e "KONG_ADMIN_LISTEN = 0.0.0.0:8001, 0.0.0.0:8444 SSL"\ -p 8000:8000 \ -p 8443:8443 \ -p 8001:8001 \ -p 8444:8444 \ kong:latest Start kong 5 curl -i http://localhost:8001/ test Kong 6 Docker pull PANTsel /konga docker run -p 1337:1337 --network kong-net --name konga-e"NODE_ENV=production"Pantsel/kongA Builds the KongA panelCopy the code

Dockerfile use

Create a dockerfile file

touch Dockerfile

example

The FROM centos RUN yum install wget RUN wget - O redis. Tar. Gz "http://download.redis.io/releases/redis-5.0.3.tar.gz" RUN tar - XVF redis.tar.gz The preceding command creates a layer 3 image. It can be simplified into the following format: The FROM centos RUN yum install wget \ && wget - O redis. Tar. Gz "http://download.redis.io/releases/redis-5.0.3.tar.gz" \ && tar -xvf redis.tar.gzCopy the code
The FROM elasticsearch: 7.12.0 ENV VERSION = 7.12.0 RUN CD/usr/share/elasticsearch/config / \ && echo "HTTP. Cors. Enabled: true" >> elasticsearch.yml \ && echo 'http.cors.allow-origin: "*"' >> elasticsearch.yml \ && cd .. /plugins/ RUN /bin/bash -c '/bin/echo -e "y" | elasticsearch-plugin install https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v${VERSION}/elasticsearch-analysis-ik-${VERSION}.zi p' EXPOSE 9200 EXPOSE 9300Copy the code
FROM python:3.7-alpine WORKDIR /code ENV FLASK_APP app.py ENV FLASK_RUN_HOST 0.0.0.0 RUN apk add --no-cache GCC musl-dev  linux-headers COPY requirements.txt requirements.txt RUN pip install -r requirements.txt COPY . . CMD ["flask", "run"]Copy the code

Build images using dockerfile

docker build -t smallsha/centos:v1 .

Combined execution of multiple commands using && links builds smaller packages based on images

FROM nginx

Execute the command

RUN the echo ‘this is a local building nginx mirror’ > / usr/share/nginx/HTML/index. HTML

The exec formats:

RUN [“./test.php”, “dev”, “offline”] is equivalent to RUN./test.php dev

COPY the contents of the machine to the machine inside

The specified path in the container. This path does not need to be created in advance. If no path exists, it will be created automatically

COPY hom* /mydir/

COPY hom? .txt /mydir/

ADD the local file to the host

The format of the ADD command is the same as that of COPY (COPY is officially recommended for the same requirements). The format of the file that ADD transfers to the host computer is tar, and it will be automatically copied and decompressed to the host computer, but the disadvantage is that it will become very slow when building the image.

CMD is executed when docker runs, run is executed when docker builds

CMD [“< executable file or command >”,””,””,…

ENTRYPOINT If the — ENTRYPOINT option is used when running docker run, the program specified by the CMD directive will be overwritten

docker run nginx:test -c /etc/nginx/new.conf

FROM nginx ENTRYPOINT ["nginx", "-c"] # change CMD [" /etc/nginx.nginx.conf "] # change CMDCopy the code

ENV definition

ENV NODE_VERSION 7.2.0 uses $ENV

Args, like ENV, are only available when dockerfiles are built. Built images are not included

VOLUME 1, the VOLUME is not specified and -v is not specified. This is a common folder.

The VOLUME folder can be shared between different containers, but cannot be changed locally.

3. Specify a -v folder. This folder can be shared between containers and can be modified locally.

VOLUME [“< path 1>”, “< path 2>”…

EXPOSE declares ports in the container, and Docker run -p randomly maps ports in the container when executing the container

WORKDIR Specifies the working directory

The USER command is used to specify the USER and USER group that runs subsequent commands.

HEALTHCHECK specifies a program or directive to monitor the health of the Docker container service.

ONBUILD is used to delay the execution of the build command


Docker – compose

The installation

Sudo curl – L “github.com/docker/comp… -s)-$(uname -m)” -o /usr/local/bin/docker-compose

sudo chmod +x /usr/local/bin/docker-compose

sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose

docker-compose –version

Create the docker-comemage. yml file

touch docker-compose.yml

example

Yaml configuration version: '3.7' # specifies which version of compose this YML compliant is composed to. Services: web: build:. # Specify an image context path: ports: - "55:5000 "redis: image: "redis:alpine"Copy the code
Version: "3.7" services: webapp: build: context:./dir # context path dockerFile: dockerfile -alternate # Command: python manage.py runServer 0.0.0.0:8000 volumes: -.:/code links: -db args: buildno: Add the build parameter, which is the environment variable labels that can only be accessed during the build process: Description =Accounting webapp" - "com.example.department=Finance" - "Com.example. label-with-empty-value" target: prod # Multi-layer build, can specify which layer to build.Copy the code
Version: '2' 'compose version 'services:' service id 'Web:' sub-service id 'image: dockercloud/hello-world' Redis: image: redis links: 'Set up connection between containers' - Web Networks: - back-tier lb: image: dockercloud/haproxy ports: - 80:80 links: - web networks: - front-tier - back-tier volumes: 'mount a directory or an existing data volume container' - / var/run/docker. The sock: / var/run/docker. The sock networks: front - tier: driver: bridge back - tier: driver: bridgeCopy the code
Version: "2.2" Services: ElasticSearch: image: ElasticSearch :7.4.2 restart: always ports: - "9200:9200" - "9300:9300" networks: - elastic environment: - "discovery.type=single-node" kibana: image: Kibana :7.4.2 Ports: - "5601:5601" Depends_on: - ElasticSearch Networks: - Elastic Networks: Elastic: Driver: BridgeCopy the code

Start the application

docker-compose up

Start the container and run in the background

docker-compose up -d

Docker-compose restart pause unpause rm delete container stop start docker-compose ps docker-compose restart pause unpause rm delete container stop start build ps

It goes into the container

docker-compose exec nginx bash

View logs -f Parameter Displays logs in real time

docker-compose logs nginx

Verify the docker-compose file is correct

docker-compose config -q

Cap_add, CAP_DROP Adds or removes host kernel functionality owned by the container.

Cap_drop: -sys_ptrace # Disable ptrace permissionCopy the code

cgroup_parent

Cgroup_parent: m-executor-abcd # Specifies the parent Cgroup group for the container, meaning that the group's resource limits will be inherited.Copy the code

Command overrides the default command that the container starts

command: [“bundle”, “exec”, “thin”, “-p”, “3000”]

Container_name Specifies the name of the build container

depends_on

Version: "3.7" services: web: build:. Depends_on: # Start the services in dependency order. In the following example, DB and Redis are started before Web is started. - db - redis redis: image: redis db: image: postgresCopy the code

Deploy specifies the configuration related to the deployment and running of the service.


Docker – compose choreography

www.cnblogs.com/wj5633/p/67…

The docker manual

Wiki.jikexueyuan.com/project/doc…

Upload mirrors to docker Hub

www.cnblogs.com/wherein/p/6…

Environment configuration (blog) (especially good PHP learning article)

www.awaimai.com/671.html

Blog.csdn.net/relax_hb/ar… Docker introduction

Blog.csdn.net/jiang_xinxi… Blog technology used by Docker

Download.docker.com/mac/stable/… Docker download link

www.cnblogs.com/zoulifeng20… Install the brew

www.cnblogs.com/LO-gin/p/69… The PHP environment setup details the parameters of each command

www.cnblogs.com/qinyujie/p/… Docker install LNMP environment (actual installation successful)

Blog.csdn.net/cmzsteven/a… Remove the container

Resolve the conflict

Blog.csdn.net/qq_35981283… Install the rabbitmq

Blog.csdn.net/lkxlaz/arti… Brew Password for installing the mysql database: SMALLsha@123

Blog.csdn.net/weixin_4022… Docker installation swoole

If the management database software fails to be connected, run the v command

ALTER USER root@localhost IDENTIFIED WITH mysql_native_password BY ‘SMALLsha@123’;

If the container cannot be mounted to the host, create a new container and mount it to the host. Then return to the container (create folder on the host).

View the php.ini location

/usr/local/php/bin/php –ini

Here is a copy of nginx configuration PHP

location ~ \.php(.*)$ { root /var/www/html/; Fastcgi_pass 172.17.0.3:9000; fastcgi_index index.php; fastcgi_split_path_info ^((? U).+\.php)(/? . +) $; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info; include fastcgi_params; }Copy the code