Docker筆記-Docker Compose

Docker筆記-Docker Compose

Compose 是用于定義和運行多容器 Docker 應用程序的工具,通過 Compose 您可以使用 YML 文件來配置應用

程序需要的所有服務。然后,使用一個命令,就可以從 YML 文件配置中創建并啟動所有服務。

Compose 使用的三個步驟:

  • 使用 Dockerfile 定義應用程序的環境。
  • 使用docker-compose.yml 定義構成應用程序的服務,這樣它們可以在隔離環境中一起運行。
  • 最后,執行 docker-compose up 命令來啟動并運行整個應用程序。

docker-compose.yml 的配置案例如下(配置參數參考下文):

# yaml配置實例
version: '3'
services:web:build: .ports:- "5000:5000"volumes:- .:/code- logvolume01:/var/loglinks:- redisredis:image: redis
volumes:logvolume01: {}

1、Compose 安裝

Linux 上我們可以從 Github 上下載它的二進制包來使用,最新發行的版本地址:

https://github.com/docker/compose/releases

運行以下命令以下載 Docker Compose 的當前穩定版本:

# https://github.com/docker/compose/releases/download/1.24.1/docker-compose-Linux-x86_64
$ sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
[root@zsx ~]# sudo curl -L "https://github.com/docker/compose/releases/download/1.24.1/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose% Total    % Received % Xferd  Average Speed   Time    Time     Time  CurrentDload  Upload   Total   Spent    Left  Speed
100   633  100   633    0     0    980      0 --:--:-- --:--:-- --:--:--   979
100 15.4M  100 15.4M    0     0  2042k      0  0:00:07  0:00:07 --:--:-- 2573k

要安裝其他版本的 Compose,請替換 1.24.1

將可執行權限應用于二進制文件:

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

創建軟鏈:

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

測試是否安裝成功:

$ docker-compose --version
docker-compose version 1.24.1, build 4667896b

注意: 對于 alpine,需要以下依賴包: py-pip,python-dev,libffi-dev,openssl-dev,gcc,libc-dev 和

make。

安裝方式二:

# 安裝pip
$ yum -y install epel-release
$ yum -y install python-pip# 確認版本
$ pip --version# 更新pip
$ pip install --upgrade pip# 安裝docker-compose
$ pip install docker-compose # 查看版本
$ docker-compose version

安裝補全工具:

# 安裝
$ yum install bash-completion# 下載docker-compose腳本
$ curl -L https://raw.githubusercontent.com/docker/compose/$(docker-compose version --short)/contrib/completion/bash/docker-compose > /etc/bash_completion.d/docker-compose

2、使用

2.1 準備

創建一個測試目錄:

$ mkdir composetest
$ cd composetest

在測試目錄中創建一個名為 app.py 的文件,并復制粘貼以下內容:

composetest/app.py 文件代碼:

import timeimport redis
from flask import Flaskapp = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)def get_hit_count():retries = 5while True:try:return cache.incr('hits')except redis.exceptions.ConnectionError as exc:if retries == 0:raise excretries -= 1time.sleep(0.5)@app.route('/')
def hello():count = get_hit_count()return 'Hello World! I have been seen {} times.\n'.format(count)

在此示例中,redis 是應用程序網絡上的 redis 容器的主機名,該主機使用的端口為 6379。

在 composetest 目錄中創建另一個名為 requirements.txt 的文件,內容如下:

flask
redis

2.2 創建Dockerfile文件

在 composetest 目錄中,創建一個名為的文件 Dockerfile,內容如下:

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"]

Dockerfile 內容解釋:

  • FROM python:3.7-alpine:從 Python 3.7 映像開始構建鏡像。

  • WORKDIR /code:將工作目錄設置為 /code。

  • ENV FLASK_APP app.py && ENV FLASK_RUN_HOST 0.0.0.0:設置 flask 命令使用的環境變量。

  • RUN apk add --no-cache gcc musl-dev linux-headers:安裝 gcc,以便諸如 MarkupSafe 和

    SQLAlchemy 之類的 Python 包可以編譯加速。

  • COPY requirements.txt requirements.txt && RUN pip install -r requirements.txt

    復制 requirements.txt 并安裝 Python 依賴項。

  • COPY . .:將 . 項目中的當前目錄復制到 . 鏡像中的工作目錄。

  • CMD ["flask", "run"]:容器提供默認的執行命令為:flask run。

2.3 創建 docker-compose.yml

在測試目錄中創建一個名為 docker-compose.yml 的文件,然后粘貼以下內容:

docker-compose.yml配置文件:

# yaml配置
version: '3'
services:web:build: .ports:- "5000:5000"redis:image: "redis:alpine"

該 Compose 文件定義了兩個服務:web 和 redis。

  • web:該 web 服務使用從 Dockerfile 當前目錄中構建的鏡像。然后,它將容器和主機綁定到暴露的端口

    5000。此示例服務使用 Flask Web 服務器的默認端口 5000 。

  • redis:該 redis 服務使用 Docker Hub 的公共 Redis 映像。

2.4 使用Compose命令構建和運行您的應用

在測試目錄中,執行以下命令來啟動應用程序:

$ docker-compose up

如果你想在后臺執行該服務可以加上 -d 參數:

$ docker-compose up -d
[root@zsx composetest]# docker-compose up
Building web
Step 1/9 : FROM python:3.7-alpine---> f0c1a69798c7
Step 2/9 : WORKDIR /code---> Using cache---> 70b58a88c05f
Step 3/9 : ENV FLASK_APP app.py---> Using cache---> 21621b425f6d
Step 4/9 : ENV FLASK_RUN_HOST 0.0.0.0---> Using cache---> 9d02c3c996ee
Step 5/9 : RUN apk add --no-cache gcc musl-dev linux-headers---> Running in ee5cc90a40a3
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/main/x86_64/APKINDEX.tar.gz
fetch https://dl-cdn.alpinelinux.org/alpine/v3.14/community/x86_64/APKINDEX.tar.gz
(1/13) Installing libgcc (10.3.1_git20210424-r2)
(2/13) Installing libstdc++ (10.3.1_git20210424-r2)
(3/13) Installing binutils (2.35.2-r2)
(4/13) Installing libgomp (10.3.1_git20210424-r2)
(5/13) Installing libatomic (10.3.1_git20210424-r2)
(6/13) Installing libgphobos (10.3.1_git20210424-r2)
(7/13) Installing gmp (6.2.1-r0)
(8/13) Installing isl22 (0.22-r0)
(9/13) Installing mpfr4 (4.1.0-r0)
(10/13) Installing mpc1 (1.2.1-r0)
(11/13) Installing gcc (10.3.1_git20210424-r2)
(12/13) Installing linux-headers (5.10.41-r0)
(13/13) Installing musl-dev (1.2.2-r3)
Executing busybox-1.33.1-r6.trigger
OK: 140 MiB in 48 packages
Removing intermediate container ee5cc90a40a3---> bc278a142ea4
Step 6/9 : COPY requirements.txt requirements.txt---> 5cf43856a885
Step 7/9 : RUN pip install -r requirements.txt---> Running in c450bb22ca48
Collecting flaskDownloading Flask-2.0.2-py3-none-any.whl (95 kB)
Collecting redisDownloading redis-4.0.1-py3-none-any.whl (118 kB)
Collecting Werkzeug>=2.0Downloading Werkzeug-2.0.2-py3-none-any.whl (288 kB)
Collecting click>=7.1.2Downloading click-8.0.3-py3-none-any.whl (97 kB)
Collecting Jinja2>=3.0Downloading Jinja2-3.0.3-py3-none-any.whl (133 kB)
Collecting itsdangerous>=2.0Downloading itsdangerous-2.0.1-py3-none-any.whl (18 kB)
Collecting deprecatedDownloading Deprecated-1.2.13-py2.py3-none-any.whl (9.6 kB)
Collecting importlib-metadataDownloading importlib_metadata-4.8.2-py3-none-any.whl (17 kB)
Collecting MarkupSafe>=2.0Downloading MarkupSafe-2.0.1-cp37-cp37m-musllinux_1_1_x86_64.whl (30 kB)
Collecting wrapt<2,>=1.10Downloading wrapt-1.13.3-cp37-cp37m-musllinux_1_1_x86_64.whl (78 kB)
Collecting zipp>=0.5Downloading zipp-3.6.0-py3-none-any.whl (5.3 kB)
Collecting typing-extensions>=3.6.4Downloading typing_extensions-4.0.0-py3-none-any.whl (22 kB)
Installing collected packages: zipp, typing-extensions, wrapt, MarkupSafe, importlib-metadata, Werkzeug, Jinja2, itsdangerous, deprecated, click, redis, flask
Successfully installed Jinja2-3.0.3 MarkupSafe-2.0.1 Werkzeug-2.0.2 click-8.0.3 deprecated-1.2.13 flask-2.0.2 importlib-metadata-4.8.2 itsdangerous-2.0.1 redis-4.0.1 typing-extensions-4.0.0 wrapt-1.13.3 zipp-3.6.0
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv
WARNING: You are using pip version 21.2.4; however, version 21.3.1 is available.
You should consider upgrading via the '/usr/local/bin/python -m pip install --upgrade pip' command.
Removing intermediate container c450bb22ca48---> b404ea962607
Step 8/9 : COPY . .---> b3ebb62f5047
Step 9/9 : CMD ["flask", "run"]---> Running in d59641e0eb5d
Removing intermediate container d59641e0eb5d---> 543598e9ff15
Successfully built 543598e9ff15
Successfully tagged composetest_web:latest
WARNING: Image for service web was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Pulling redis (redis:alpine)...
alpine: Pulling from library/redis
97518928ae5f: Already exists
66f8c4150d27: Pull complete
09a8bf17a0bf: Pull complete
e547313af8e7: Pull complete
335eeadfbde0: Pull complete
7151fc2c01eb: Pull complete
Digest: sha256:50fc99c529b81432a592fa76354783d7fc3ba479a92fc810cbf669138c4138b7
Status: Downloaded newer image for redis:alpine
Creating composetest_web_1   ... done
Creating composetest_redis_1 ... done
Attaching to composetest_redis_1, composetest_web_1
redis_1  | 1:C 17 Nov 2021 12:47:55.857 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1  | 1:C 17 Nov 2021 12:47:55.857 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1  | 1:C 17 Nov 2021 12:47:55.857 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1  | 1:M 17 Nov 2021 12:47:55.858 * monotonic clock: POSIX clock_gettime
redis_1  | 1:M 17 Nov 2021 12:47:55.858 * Running mode=standalone, port=6379.
redis_1  | 1:M 17 Nov 2021 12:47:55.859 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1  | 1:M 17 Nov 2021 12:47:55.859 # Server initialized
redis_1  | 1:M 17 Nov 2021 12:47:55.859 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1  | 1:M 17 Nov 2021 12:47:55.859 * Ready to accept connections
web_1    |  * Serving Flask app 'app.py' (lazy loading)
web_1    |  * Environment: production
web_1    |    WARNING: This is a development server. Do not use it in a production deployment.
web_1    |    Use a production WSGI server instead.
web_1    |  * Debug mode: off
web_1    | /usr/local/lib/python3.7/site-packages/redis/connection.py:72: UserWarning: redis-py works best with hiredis. Please consider installing
web_1    |   warnings.warn(msg)
web_1    |  * Running on all addresses.
web_1    |    WARNING: This is a development server. Do not use it in a production deployment.
web_1    |  * Running on http://172.19.0.3:5000/ (Press CTRL+C to quit)
web_1    | 172.19.0.1 - - [17/Nov/2021 12:48:48] "GET / HTTP/1.1" 200 -
web_1    | 172.19.0.1 - - [17/Nov/2021 12:48:48] "GET /favicon.ico HTTP/1.1" 404 -
web_1    | 192.168.157.185 - - [17/Nov/2021 12:49:11] "GET / HTTP/1.1" 200 -
web_1    | 192.168.157.185 - - [17/Nov/2021 12:49:11] "GET /favicon.ico HTTP/1.1" 404 -
web_1    | 192.168.157.185 - - [17/Nov/2021 12:49:14] "GET / HTTP/1.1" 200 -
web_1    | 192.168.157.185 - - [17/Nov/2021 12:49:15] "GET / HTTP/1.1" 200 -

在這里插入圖片描述

在這里插入圖片描述

3、yml 配置指令參考

3.1 version

指定本 yml 依從的 compose 哪個版本制定的。

3.2 build

指定為構建鏡像上下文路徑:

例如 webapp 服務,指定為從上下文路徑 ./dir/Dockerfile 所構建的鏡像:

version: "3.7"
services:webapp:build: ./dir

或者,作為具有在上下文指定的路徑的對象,以及可選的 Dockerfile 和 args:

version: "3.7"
services:webapp:build:context: ./dirdockerfile: Dockerfile-alternateargs:buildno: 1labels:- "com.example.description=Accounting webapp"- "com.example.department=Finance"- "com.example.label-with-empty-value"target: prod
  • context:上下文路徑。
  • dockerfile:指定構建鏡像的 Dockerfile 文件名。
  • args:添加構建參數,這是只能在構建過程中訪問的環境變量。
  • labels:設置構建鏡像的標簽。
  • target:多層構建,可以指定構建哪一層。

3.3 cap_add,cap_drop

添加或刪除容器擁有的宿主機的內核功能。

cap_add:- ALL # 開啟全部權限cap_drop:- SYS_PTRACE # 關閉 ptrace權限

3.4 cgroup_parent

為容器指定父 cgroup 組,意味著將繼承該組的資源限制。

cgroup_parent: m-executor-abcd

3.5 command

覆蓋容器啟動的默認命令。

command: ["bundle", "exec", "thin", "-p", "3000"]

3.6 container_name

指定自定義容器名稱,而不是生成的默認名稱。

container_name: my-web-container

3.7 depends_on

設置依賴關系。

  • docker-compose up:以依賴性順序啟動服務。在以下示例中,先啟動 db 和 redis ,才會啟動 web。

  • docker-compose up SERVICE :自動包含 SERVICE 的依賴項。在以下示例中,docker-compose up web

    還將創建并啟動 db 和 redis。

  • docker-compose stop :按依賴關系順序停止服務。在以下示例中,web 在 db 和 redis 之前停止。

version: "3.7"
services:web:build: .depends_on:- db- redisredis:image: redisdb:image: postgres

注意:web 服務不會等待 redis db 完全啟動 之后才啟動。

3.8 deploy

指定與服務的部署和運行有關的配置,只在 swarm 模式下才會有用。

version: "3.7"
services:redis:image: redis:alpinedeploy:mode: replicatedreplicas: 6endpoint_mode: dnsrrlabels: description: "This redis service label"resources:limits:cpus: '0.50'memory: 50Mreservations:cpus: '0.25'memory: 20Mrestart_policy:condition: on-failuredelay: 5smax_attempts: 3window: 120s

可以選參數:

endpoint_mode:訪問集群服務的方式。

# Docker集群服務一個對外的虛擬ip,所有的請求都會通過這個虛擬ip到達集群服務內部的機器
endpoint_mode: vip # DNS輪詢(DNSRR),所有的請求會自動輪詢獲取到集群ip列表中的一個ip地址
endpoint_mode: dnsrr

labels:在服務上設置標簽。可以用容器上的 labels(跟 deploy 同級的配置) 覆蓋 deploy 下的 labels。

mode:指定服務提供的模式。

  • replicated:復制服務,復制指定服務到集群的機器上。

  • global:全局服務,服務將部署至集群的每個節點。

  • 圖解:下圖中黃色的方塊是 replicated 模式的運行情況,灰色方塊是 global 模式的運行情況。

    在這里插入圖片描述

replicas:mode 為 replicated 時,需要使用此參數配置具體運行的節點數量。

resources:配置服務器資源使用的限制,例如上例子,配置 redis 集群運行需要的 cpu 的百分比 和 內存的占

用。避免占用資源過高出現異常。

restart_policy:配置如何在退出容器時重新啟動容器。

  • condition:可選 none,on-failure 或者 any(默認值:any)。
  • delay:設置多久之后重啟(默認值:0)。
  • max_attempts:嘗試重新啟動容器的次數,超出次數,則不再嘗試(默認值:一直重試)。
  • window:設置容器重啟超時時間(默認值:0)。

rollback_config:配置在更新失敗的情況下應如何回滾服務。

  • parallelism:一次要回滾的容器數。如果設置為0,則所有容器將同時回滾。

  • delay:每個容器組回滾之間等待的時間(默認為0s)。

  • failure_action:如果回滾失敗,該怎么辦。其中一個 continue 或者 pause(默認pause)。

  • monitor:每個容器更新后,持續觀察是否失敗了的時間 (ns|us|ms|s|m|h)(默認為0s)。

  • max_failure_ratio:在回滾期間可以容忍的故障率(默認為0)。

  • order:回滾期間的操作順序。其中一個 stop-first(串行回滾),或者 start-first(并行回滾)(默認 stop-

    first )。

update_config:配置應如何更新服務,對于配置滾動更新很有用。

  • parallelism:一次更新的容器數。

  • delay:在更新一組容器之間等待的時間。

  • failure_action:如果更新失敗,該怎么辦。其中一個 continue,rollback 或者pause (默認:pause)。

  • monitor:每個容器更新后,持續觀察是否失敗了的時間 (ns|us|ms|s|m|h)(默認為0s)。

  • max_failure_ratio:在更新過程中可以容忍的故障率。

  • order:回滾期間的操作順序。其中一個 stop-first(串行回滾),或者 start-first(并行回滾)(默認stop-

    first)。

注:僅支持 V3.4 及更高版本。

3.9 devices

指定設備映射列表。

devices:- "/dev/ttyUSB0:/dev/ttyUSB0"

3.10 dns

自定義 DNS 服務器,可以是單個值或列表的多個值。

dns: 8.8.8.8dns:- 8.8.8.8- 9.9.9.9

3.11 dns_search

自定義 DNS 搜索域,可以是單個值或列表。

dns_search: example.comdns_search:- dc1.example.com- dc2.example.com

3.12 entrypoint

覆蓋容器默認的 entrypoint。

entrypoint: /code/entrypoint.sh

也可以是以下格式:

entrypoint:- php- -d- zend_extension=/usr/local/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so- -d- memory_limit=-1- vendor/bin/phpunit

3.13 env_file

從文件添加環境變量,可以是單個值或列表的多個值。

env_file: .env

也可以是列表格式:

env_file:- ./common.env- ./apps/web.env- /opt/secrets.env

3.14 environment

添加環境變量。您可以使用數組或字典、任何布爾值,布爾值需要用引號引起來,以確保 YML 解析器不會將其轉

換為 True 或 False。

environment:RACK_ENV: developmentSHOW: 'true'

3.15 expose

暴露端口,但不映射到宿主機,只被連接的服務訪問。

僅可以指定內部端口為參數:

expose:- "3000"- "8000"

3.16 extra_hosts

添加主機名映射,類似 docker client --add-host。

extra_hosts:- "somehost:162.242.195.82"- "otherhost:50.31.209.229"

以上會在此服務的內部容器中 /etc/hosts 創建一個具有 ip 地址和主機名的映射關系:

162.242.195.82  somehost
50.31.209.229   otherhost

3.17 healthcheck

用于檢測 docker 服務是否健康運行。

healthcheck:test: ["CMD", "curl", "-f", "http://localhost"] # 設置檢測程序interval: 1m30s # 設置檢測間隔timeout: 10s # 設置檢測超時時間retries: 3 # 設置重試次數start_period: 40s # 啟動后,多少秒開始啟動檢測程序

3.18 image

指定容器運行的鏡像,以下格式都可以:

image: redis
image: ubuntu:14.04
image: tutum/influxdb
image: example-registry.com:4000/postgresql
image: a4bc65fd # 鏡像id

3.19 logging

服務的日志記錄配置。

driver:指定服務容器的日志記錄驅動程序,默認值為json-file。有以下三個選項

driver: "json-file"
driver: "syslog"
driver: "none"

僅在 json-file 驅動程序下,可以使用以下參數,限制日志得數量和大小。

logging:driver: json-fileoptions:max-size: "200k" # 單個文件大小為200kmax-file: "10" # 最多10個文件

當達到文件限制上限,會自動刪除舊得文件。

syslog 驅動程序下,可以使用 syslog-address 指定日志接收地址。

logging:driver: syslogoptions:syslog-address: "tcp://192.168.0.42:123"

3.20 network_mode

設置網絡模式。

network_mode: "bridge"
network_mode: "host"
network_mode: "none"
network_mode: "service:[service name]"
network_mode: "container:[container name/id]"

networks 配置容器連接的網絡,引用頂級 networks 下的條目 。

services:some-service:networks:some-network:aliases:- alias1other-network:aliases:- alias2
networks:some-network:# Use a custom driverdriver: custom-driver-1other-network:# Use a custom driver which takes special optionsdriver: custom-driver-2

aliases:同一網絡上的其他容器可以使用服務名稱或此別名來連接到對應容器的服務。

3.21 restart

  • no:是默認的重啟策略,在任何情況下都不會重啟容器。
  • always:容器總是重新啟動。
  • on-failure:在容器非正常退出時(退出狀態非0),才會重啟容器。
  • unless-stopped:在容器退出時總是重啟容器,但是不考慮在Docker守護進程啟動時就已經停止了的容器
restart: "no"
restart: always
restart: on-failure
restart: unless-stopped

注:swarm 集群模式,請改用 restart_policy。

3.22 secrets

存儲敏感數據,例如密碼:

version: "3.1"
services:mysql:image: mysqlenvironment:MYSQL_ROOT_PASSWORD_FILE: /run/secrets/my_secretsecrets:- my_secretsecrets:my_secret:file: ./my_secret.txt

3.23 security_opt

修改容器默認的 schema 標簽。

security-opt:- label:user:USER   # 設置容器的用戶標簽- label:role:ROLE   # 設置容器的角色標簽- label:type:TYPE   # 設置容器的安全策略標簽- label:level:LEVEL  # 設置容器的安全等級標簽

3.24 stop_grace_period

指定在容器無法處理 SIGTERM (或者任何 stop_signal 的信號),等待多久后發送 SIGKILL 信號關閉容器。

stop_grace_period: 1s # 等待 1 秒
stop_grace_period: 1m30s # 等待 1 分 30 秒 

默認的等待時間是 10 秒。

3.25 stop_signal

設置停止容器的替代信號,默認情況下使用 SIGTERM。

以下示例,使用 SIGUSR1 替代信號 SIGTERM 來停止容器。

stop_signal: SIGUSR1

3.26 sysctls

設置容器中的內核參數,可以使用數組或字典格式。

sysctls:net.core.somaxconn: 1024net.ipv4.tcp_syncookies: 0sysctls:- net.core.somaxconn=1024- net.ipv4.tcp_syncookies=0

3.27 tmpfs

在容器內安裝一個臨時文件系統,可以是單個值或列表的多個值。

tmpfs: /runtmpfs:- /run- /tmp

3.28 ulimits

覆蓋容器默認的 ulimit。

ulimits:nproc: 65535nofile:soft: 20000hard: 40000

3.29 volumes

將主機的數據卷或著文件掛載到容器里。

version: "3.7"
services:db:image: postgres:latestvolumes:- "/localhost/postgres.sock:/var/run/postgres/postgres.sock"- "/localhost/data:/var/lib/postgresql/data"

4、Docker Compose例子

# 案例地址
https://docs.docker.com/compose/gettingstarted/

4.1 Step1 新建文件夾

$ mkdir composetest
$ cd composetest

4.2 Step2 新建app.py文件

import timeimport redis
from flask import Flaskapp = Flask(__name__)
cache = redis.Redis(host='redis', port=6379)def get_hit_count():retries = 5while True:try:return cache.incr('hits')except redis.exceptions.ConnectionError as exc:if retries == 0:raise excretries -= 1time.sleep(0.5)@app.route('/')
def hello():count = get_hit_count()return 'Hello World! I have been seen {} times.\n'.format(count)

4.3 Step3 創建requirements.txt文件

flask
redis

4.4 Step4 創建Dockerfile文件

# syntax=docker/dockerfile:1
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
EXPOSE 5000
COPY . .
CMD ["flask", "run"]

4.5 Step5 創建docker-compose.yml文件

version: "3.9"
services:web:build: .ports:- "5000:5000"redis:image: "redis:alpine"

4.6 Step6 構建

$ docker-compose up

4.7 Step7 訪問

$ docker image ls
[root@zsx zhangshixing]# docker image ls
REPOSITORY            TAG          IMAGE ID       CREATED          SIZE
composetest_web       latest       543598e9ff15   16 minutes ago   183MB
diytomcat             latest       3ca521cc579e   9 hours ago      651MB
nginx                 latest       e9ce56a96f8e   19 hours ago     141MB
tomcat                latest       5db6fed793e9   40 hours ago     680MB
ubuntu                v2           8ea6534ccd35   2 days ago       137MB
redis                 alpine       5c08f13a2b92   4 days ago       32.4MB
python                3.7-alpine   f0c1a69798c7   4 days ago       41.9MB
tomcat                <none>       b0e0b0a92cf9   3 weeks ago      680MB
hello-world           latest       feb5d9fea6a5   7 weeks ago      13.3kB
centos                latest       5d0da3dc9764   2 months ago     231MB
portainer/portainer   latest       580c0e4e98b0   8 months ago     79.1MB
centos                6.7          9f1de3c6ad53   2 years ago      191MB
ubuntu                15.10        9b9cb95443b5   5 years ago      137MB
training/webapp       latest       6fae60ef3446   6 years ago      349MB
$ docker service ls
[root@zsx zhangshixing]# docker service ls
Error response from daemon: This node is not a swarm manager. Use "docker swarm init" or "docker swarm join" to connect this node to swarm and try again.
$ docker network ls
[root@zsx zhangshixing]# docker network ls
NETWORK ID     NAME                  DRIVER    SCOPE
22a861c9adb3   bridge                bridge    local
3ec11aa11df0   composetest_default   bridge    local
87f220cd32d2   host                  host      local
d61d5b0273fb   none                  null      local
9e3b5ce80e32   test-net              bridge    local
$ curl http://localhost:5000
Hello World! I have been seen 14 times.

4.8 Step8 其它的命令

[root@zsx ~]# docker-compose --helpUsage:  docker compose [OPTIONS] COMMANDDocker ComposeOptions:--ansi string                Control when to print ANSI control characters ("never"|"always"|"auto") (default"auto")--compatibility              Run compose in backward compatibility mode--env-file string            Specify an alternate environment file.-f, --file stringArray           Compose configuration files--profile stringArray        Specify a profile to enable--project-directory string   Specify an alternate working directory(default: the path of the, first specified, Compose file)-p, --project-name string        Project nameCommands:build       Build or rebuild servicesconvert     Converts the compose file to platform's canonical formatcp          Copy files/folders between a service container and the local filesystemcreate      Creates containers for a service.down        Stop and remove containers, networksevents      Receive real time events from containers.exec        Execute a command in a running container.images      List images used by the created containerskill        Force stop service containers.logs        View output from containersls          List running compose projectspause       Pause servicesport        Print the public port for a port binding.ps          List containerspull        Pull service imagespush        Push service imagesrestart     Restart service containersrm          Removes stopped service containersrun         Run a one-off command on a service.start       Start servicesstop        Stop servicestop         Display the running processesunpause     Unpause servicesup          Create and start containersversion     Show the Docker Compose version informationRun 'docker compose COMMAND --help' for more information on a command.

可以看到 docker-compose 的命令格式為:

$ docker compose [OPTIONS] COMMAND

具體的一些命令:

# 用于啟動使用Docker Compose編排的多個容器
# 啟動所有服務
$ docker-compose up
$ docker-compose up [OPTIONS] [SERVICE...]# 在后臺啟動所有服務
$ docker-compose up -d# 在后臺所有啟動服務,指定編排文件
$ docker-compose -f docker-compose.yml up -d# 用于列出由Docker Compose管理的容器的狀態
$ docker-compose ps
$ docker-compose ps [OPTIONS] [SERVICE...]# 指定配置文件
$ docker-compose -f <file> ps# 顯示詳細信息
$ docker-compose ps -a# 停止正在運行的容器
$ docker-compose stop
$ docker-compose stop [OPTIONS] [SERVICE...]# 用于停止和移除由docker-compose up創建的容器、網絡和卷
$ docker-compose down
$ docker-compose down [OPTIONS]# 除關聯的卷
$ docker-compose down --volumes# 用于查看由docker-compose啟動的服務的日志
$ docker-compose logs
$ docker-compose logs [OPTIONS] [SERVICE...]# 指定服務名稱,默認情況下docker-compose logs會顯示所有服務的日志,如果只想查看特定服務的日志,可以指定服務名稱作為參數
$ docker-compose logs <service1> <service2># 構建(重新構建)項目中的服務容器
$ docker-compose build
$ docker-compose build [OPTIONS] [SERVICE...]# 拉取服務依賴的鏡像
$ docker-compose pull
$ docker-compose pull [OPTIONS] [SERVICE...]# 用于重新啟動由docker-compose啟動的服務容器
$ docker-compose restart
$ docker-compose restart [OPTIONS] [SERVICE...]# 刪除所有(停止狀態的)服務容器
$ docker-compose rm
$ docker-compose rm [OPTIONS] [SERVICE...]# 用于啟動由docker-compose管理的服務容器
$ docker-compose start
$ docker-compose start [SERVICE...]# 在指定服務上執行一個命令
$ docker-compose run
$ docker-compose run [OPTIONS] SERVICE [COMMAND] [ARGS...]$ docker-compose run <service> <command>
# 查看web服務可用的環境變量
$ docker-compose run web env # 附加到終端,默認情況下,docker-compose run命令會啟動一個新容器并在其中運行命令,然后退出,如果想要在容器中進行交互操作,可以使用-it選項將命令附加到終端
$ docker-compose run -it <service> <command># 用于擴展或縮小Docker Compose中的服務實例數量
$ docker-compose scale
$ docker-compose scale <service1>=<num1> <service2>=<num2> ...# 用于暫停運行中的服務容器
$ docker-compose pause
$ docker-compose pause [SERVICE...]# 用于停止運行中的服務容器,它會立即終止容器的運行,類似于強制執行Ctrl+C中斷
$ docker-compose kill
$ docker-compose kill [OPTIONS] [SERVICE...]# 用于驗證和顯示由docker-compose.yml文件定義的服務配置
$ dokcer-compose config
$ docker-compose config [OPTIONS] [SERVICE...]# 用于創建在Docker Compose文件中定義的服務的容器,但不會啟動這些容器,它主要用于預先創建容器,以便稍后通過 docker-compose start或docker-compose up命令啟動這些容器
$ docker-compose create
$ docker-compose create [OPTIONS] [SERVICE...]# 用于在運行中的服務容器中執行命令,它允許你與正在運行的容器進行交互并在其內部執行命令
$ docker-compose exec
$ docker compose exec [OPTIONS] SERVICE COMMAND [ARGS...]# 這個例子將會進入名為web的服務容器,并在容器內執行ls -l命令來列出文件和目錄
$ docker-compose exec web ls -l# 用于查看由Docker Compose管理的服務容器的端口映射情況,它允許你查看服務容器的公開端口與主機上的端口之間的映射關系
$ docker-compose port
$ docker-compose push [OPTIONS] [SERVICE...]# 用于取消暫停一個或多個由Docker Compose管理的服務容器,它允許你恢復被暫停的服務容器的正常運行狀態
$ docker-compose unpause
$ docker compose unpause [SERVICE...]# 這個例子將會取消暫停名為web和db的服務容器
$ docker-compose unpause web db  

5、yaml規則

# docker-compose.yaml核心
# https://docs.docker.com/compose/compose-file
# 3層
version:"' #版本
services:  #服務服務1:web# 服務配置imagesbuildnetwork.......服務2: redis
#其他配置 網絡/卷、全局規則
volumes:
networks:
configs:

6、快速入門 Compose and WordPress(開源博客系統)

官方文檔:https://docs.docker.com/samples/wordpress/

$ mkdir my_wordpress
$ cd my_wordpress/
# 創建docker-compose.yml
version: "3.3"services:db:image: mysql:5.7volumes:- db_data:/var/lib/mysqlrestart: alwaysenvironment:MYSQL_ROOT_PASSWORD: somewordpressMYSQL_DATABASE: wordpressMYSQL_USER: wordpressMYSQL_PASSWORD: wordpresswordpress:depends_on:- dbimage: wordpress:latestvolumes:- wordpress_data:/var/www/htmlports:- "8000:80"restart: alwaysenvironment:WORDPRESS_DB_HOST: db:3306WORDPRESS_DB_USER: wordpressWORDPRESS_DB_PASSWORD: wordpressWORDPRESS_DB_NAME: wordpress
volumes:db_data: {}wordpress_data: {}
$ docker-compose up -d  | docker-compose up
[root@zsx my_wordpress]# docker-compose up
Creating network "my_wordpress_default" with the default driver
Creating volume "my_wordpress_db_data" with default driver
Creating volume "my_wordpress_wordpress_data" with default driver
Pulling db (mysql:5.7)...
5.7: Pulling from library/mysql
a10c77af2613: Pull complete
b76a7eb51ffd: Pull complete
258223f927e4: Pull complete
2d2c75386df9: Pull complete
63e92e4046c9: Pull complete
f5845c731544: Pull complete
bd0401123a9b: Pull complete
2724b2da64fd: Pull complete
d10a7e9e325c: Pull complete
1c5fd9c3683d: Pull complete
2e35f83a12e9: Pull complete
Digest: sha256:7a3a7b7a29e6fbff433c339fc52245435fa2c308586481f2f92ab1df239d6a29
Status: Downloaded newer image for mysql:5.7
Pulling wordpress (wordpress:latest)...
latest: Pulling from library/wordpress
7d63c13d9b9b: Already exists
24b15dfd3cfa: Pulling fs layer
64625c2e355f: Pulling fs layer
275a8dd8f358: Pull complete
eb1c8ccc797a: Pull complete
0aaf98f0c33a: Pull complete
e6e7c544c3e3: Pull complete
4ae870a5fb80: Pull complete
98833c4f4a49: Pull complete
f1a6af6bf10a: Pull complete
a56ec4dacea3: Pull complete
ab49679021a9: Pull complete
62d224267322: Pull complete
50baad31f9e0: Pull complete
0dce3ac87bb9: Pull complete
6e8719cc3579: Pull complete
69628185e06b: Pull complete
3a97cd45ec02: Pull complete
abb42ef6cbf3: Pull complete
80b88db9d84e: Pull complete
ebe8bf4c22f9: Pull complete
Digest: sha256:34cc2ea05ac3622a9baf969eafc2a770339d8bdddc4ea740da9288d4a96b5fb0
Status: Downloaded newer image for wordpress:latest
Creating my_wordpress_db_1 ... done
Creating my_wordpress_wordpress_1 ... done
Attaching to my_wordpress_db_1, my_wordpress_wordpress_1
db_1         | 2021-11-17 13:36:21+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
db_1         | 2021-11-17 13:36:22+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db_1         | 2021-11-17 13:36:22+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.36-1debian10 started.
db_1         | 2021-11-17 13:36:22+00:00 [Note] [Entrypoint]: Initializing database files
db_1         | 2021-11-17T13:36:22.339349Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1         | 2021-11-17T13:36:22.811795Z 0 [Warning] InnoDB: New log files created, LSN=45790
db_1         | 2021-11-17T13:36:22.895504Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
wordpress_1  | WordPress not found in /var/www/html - copying now...
db_1         | 2021-11-17T13:36:22.967677Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 5ac7f67d-47ab-11ec-b66f-0242ac140002.
db_1         | 2021-11-17T13:36:22.990812Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
wordpress_1  | Complete! WordPress has been successfully copied to /var/www/html
wordpress_1  | No 'wp-config.php' found in /var/www/html, but 'WORDPRESS_...' variables supplied; copying 'wp-config-docker.php' (WORDPRESS_DB_HOST WORDPRESS_DB_NAME WORDPRESS_DB_PASSWORD WORDPRESS_DB_USER)
wordpress_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.3. Set the 'ServerName' directive globally to suppress this message
wordpress_1  | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.20.0.3. Set the 'ServerName' directive globally to suppress this message
wordpress_1  | [Wed Nov 17 13:36:24.552305 2021] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.51 (Debian) PHP/7.4.25 configured -- resuming normal operations
wordpress_1  | [Wed Nov 17 13:36:24.552370 2021] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
db_1         | 2021-11-17T13:36:24.948286Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
db_1         | 2021-11-17T13:36:24.948298Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
db_1         | 2021-11-17T13:36:24.948652Z 0 [Warning] CA certificate ca.pem is self signed.
db_1         | 2021-11-17T13:36:25.101761Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
db_1         | 2021-11-17 13:36:27+00:00 [Note] [Entrypoint]: Database files initialized
db_1         | 2021-11-17 13:36:27+00:00 [Note] [Entrypoint]: Starting temporary server
db_1         | 2021-11-17 13:36:27+00:00 [Note] [Entrypoint]: Waiting for server startup
db_1         | 2021-11-17T13:36:27.742491Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1         | 2021-11-17T13:36:27.748425Z 0 [Note] mysqld (mysqld 5.7.36) starting as process 75 ...
db_1         | 2021-11-17T13:36:27.757803Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1         | 2021-11-17T13:36:27.757816Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1         | 2021-11-17T13:36:27.757820Z 0 [Note] InnoDB: Uses event mutexes
db_1         | 2021-11-17T13:36:27.757822Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1         | 2021-11-17T13:36:27.757824Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1         | 2021-11-17T13:36:27.757827Z 0 [Note] InnoDB: Using Linux native AIO
db_1         | 2021-11-17T13:36:27.758223Z 0 [Note] InnoDB: Number of pools: 1
db_1         | 2021-11-17T13:36:27.758422Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1         | 2021-11-17T13:36:27.765018Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1         | 2021-11-17T13:36:27.812392Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1         | 2021-11-17T13:36:27.831530Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1         | 2021-11-17T13:36:27.852260Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1         | 2021-11-17T13:36:27.870988Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1         | 2021-11-17T13:36:27.871061Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1         | 2021-11-17T13:36:27.922228Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1         | 2021-11-17T13:36:27.923595Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1         | 2021-11-17T13:36:27.923606Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1         | 2021-11-17T13:36:27.928045Z 0 [Note] InnoDB: Waiting for purge to start
db_1         | 2021-11-17T13:36:27.978670Z 0 [Note] InnoDB: 5.7.36 started; log sequence number 2749732
db_1         | 2021-11-17T13:36:27.979192Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1         | 2021-11-17T13:36:27.987243Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1         | 2021-11-17T13:36:27.994173Z 0 [Note] InnoDB: Buffer pool(s) load completed at 211117 13:36:27
db_1         | 2021-11-17T13:36:27.995566Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1         | 2021-11-17T13:36:27.995576Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
db_1         | 2021-11-17T13:36:27.995579Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
db_1         | 2021-11-17T13:36:27.995582Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
db_1         | 2021-11-17T13:36:27.996152Z 0 [Warning] CA certificate ca.pem is self signed.
db_1         | 2021-11-17T13:36:27.996182Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
db_1         | 2021-11-17T13:36:27.998792Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1         | 2021-11-17T13:36:28.006867Z 0 [Note] Event Scheduler: Loaded 0 events
db_1         | 2021-11-17T13:36:28.007065Z 0 [Note] mysqld: ready for connections.
db_1         | Version: '5.7.36'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server (GPL)
db_1         | 2021-11-17 13:36:28+00:00 [Note] [Entrypoint]: Temporary server started.
db_1         | Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
db_1         | Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
db_1         | 2021-11-17T13:36:29.685968Z 3 [ERROR] InnoDB: posix_fallocate(): Failed to preallocate data for file ./ibdata1, desired size 67108864 bytes. Operating system error number 28. Check that the disk is not full or a disk quota exceeded. Make sure the file system supports this function. Some operating system error numbers are described at http://dev.mysql.com/doc/refman/5.7/en/operating-system-error-codes.html
db_1         | 2021-11-17T13:36:29.790284Z 3 [Warning] InnoDB: 1048576 bytes should have been written. Only 458752 bytes written. Retrying for the remaining bytes.
db_1         | Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
db_1         | Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
db_1         | 2021-11-17 13:36:30+00:00 [Note] [Entrypoint]: Creating database wordpress
db_1         | 2021-11-17 13:36:30+00:00 [Note] [Entrypoint]: Creating user wordpress
db_1         | 2021-11-17 13:36:30+00:00 [Note] [Entrypoint]: Giving user wordpress access to schema wordpress
db_1         | 
db_1         | 2021-11-17 13:36:30+00:00 [Note] [Entrypoint]: Stopping temporary server
db_1         | 2021-11-17T13:36:30.508846Z 0 [Note] Giving 0 client threads a chance to die gracefully
db_1         | 2021-11-17T13:36:30.508863Z 0 [Note] Shutting down slave threads
db_1         | 2021-11-17T13:36:30.508869Z 0 [Note] Forcefully disconnecting 0 remaining clients
db_1         | 2021-11-17T13:36:30.508873Z 0 [Note] Event Scheduler: Purging the queue. 0 events
db_1         | 2021-11-17T13:36:30.509375Z 0 [Note] Binlog end
db_1         | 2021-11-17T13:36:30.509873Z 0 [Note] Shutting down plugin 'ngram'
db_1         | 2021-11-17T13:36:30.509880Z 0 [Note] Shutting down plugin 'partition'
db_1         | 2021-11-17T13:36:30.509882Z 0 [Note] Shutting down plugin 'BLACKHOLE'
db_1         | 2021-11-17T13:36:30.509885Z 0 [Note] Shutting down plugin 'ARCHIVE'
db_1         | 2021-11-17T13:36:30.509887Z 0 [Note] Shutting down plugin 'PERFORMANCE_SCHEMA'
db_1         | 2021-11-17T13:36:30.509907Z 0 [Note] Shutting down plugin 'MRG_MYISAM'
db_1         | 2021-11-17T13:36:30.509912Z 0 [Note] Shutting down plugin 'MyISAM'
db_1         | 2021-11-17T13:36:30.509919Z 0 [Note] Shutting down plugin 'INNODB_SYS_VIRTUAL'
db_1         | 2021-11-17T13:36:30.509922Z 0 [Note] Shutting down plugin 'INNODB_SYS_DATAFILES'
db_1         | 2021-11-17T13:36:30.509924Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESPACES'
db_1         | 2021-11-17T13:36:30.509925Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN_COLS'
db_1         | 2021-11-17T13:36:30.509927Z 0 [Note] Shutting down plugin 'INNODB_SYS_FOREIGN'
db_1         | 2021-11-17T13:36:30.509929Z 0 [Note] Shutting down plugin 'INNODB_SYS_FIELDS'
db_1         | 2021-11-17T13:36:30.509931Z 0 [Note] Shutting down plugin 'INNODB_SYS_COLUMNS'
db_1         | 2021-11-17T13:36:30.509932Z 0 [Note] Shutting down plugin 'INNODB_SYS_INDEXES'
db_1         | 2021-11-17T13:36:30.509934Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLESTATS'
db_1         | 2021-11-17T13:36:30.509936Z 0 [Note] Shutting down plugin 'INNODB_SYS_TABLES'
db_1         | 2021-11-17T13:36:30.509937Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_TABLE'
db_1         | 2021-11-17T13:36:30.509939Z 0 [Note] Shutting down plugin 'INNODB_FT_INDEX_CACHE'
db_1         | 2021-11-17T13:36:30.509940Z 0 [Note] Shutting down plugin 'INNODB_FT_CONFIG'
db_1         | 2021-11-17T13:36:30.509942Z 0 [Note] Shutting down plugin 'INNODB_FT_BEING_DELETED'
db_1         | 2021-11-17T13:36:30.509944Z 0 [Note] Shutting down plugin 'INNODB_FT_DELETED'
db_1         | 2021-11-17T13:36:30.509945Z 0 [Note] Shutting down plugin 'INNODB_FT_DEFAULT_STOPWORD'
db_1         | 2021-11-17T13:36:30.509947Z 0 [Note] Shutting down plugin 'INNODB_METRICS'
db_1         | 2021-11-17T13:36:30.509949Z 0 [Note] Shutting down plugin 'INNODB_TEMP_TABLE_INFO'
db_1         | 2021-11-17T13:36:30.509950Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_POOL_STATS'
db_1         | 2021-11-17T13:36:30.509952Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE_LRU'
db_1         | 2021-11-17T13:36:30.509954Z 0 [Note] Shutting down plugin 'INNODB_BUFFER_PAGE'
db_1         | 2021-11-17T13:36:30.509955Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX_RESET'
db_1         | 2021-11-17T13:36:30.509957Z 0 [Note] Shutting down plugin 'INNODB_CMP_PER_INDEX'
db_1         | 2021-11-17T13:36:30.509958Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM_RESET'
db_1         | 2021-11-17T13:36:30.509960Z 0 [Note] Shutting down plugin 'INNODB_CMPMEM'
db_1         | 2021-11-17T13:36:30.509962Z 0 [Note] Shutting down plugin 'INNODB_CMP_RESET'
db_1         | 2021-11-17T13:36:30.509963Z 0 [Note] Shutting down plugin 'INNODB_CMP'
db_1         | 2021-11-17T13:36:30.509965Z 0 [Note] Shutting down plugin 'INNODB_LOCK_WAITS'
db_1         | 2021-11-17T13:36:30.509966Z 0 [Note] Shutting down plugin 'INNODB_LOCKS'
db_1         | 2021-11-17T13:36:30.509968Z 0 [Note] Shutting down plugin 'INNODB_TRX'
db_1         | 2021-11-17T13:36:30.509970Z 0 [Note] Shutting down plugin 'InnoDB'
db_1         | 2021-11-17T13:36:30.510064Z 0 [Note] InnoDB: FTS optimize thread exiting.
db_1         | 2021-11-17T13:36:30.511766Z 0 [Note] InnoDB: Starting shutdown...
db_1         | 2021-11-17T13:36:30.613210Z 0 [Note] InnoDB: Dumping buffer pool(s) to /var/lib/mysql/ib_buffer_pool
db_1         | 2021-11-17T13:36:30.614166Z 0 [Note] InnoDB: Buffer pool(s) dump completed at 211117 13:36:30
db_1         | 2021-11-17T13:36:31.932081Z 0 [Note] InnoDB: Shutdown completed; log sequence number 12659654
db_1         | 2021-11-17T13:36:31.933189Z 0 [Note] InnoDB: Removed temporary tablespace data file: "ibtmp1"
db_1         | 2021-11-17T13:36:31.933204Z 0 [Note] Shutting down plugin 'MEMORY'
db_1         | 2021-11-17T13:36:31.933210Z 0 [Note] Shutting down plugin 'CSV'
db_1         | 2021-11-17T13:36:31.933214Z 0 [Note] Shutting down plugin 'sha256_password'
db_1         | 2021-11-17T13:36:31.933216Z 0 [Note] Shutting down plugin 'mysql_native_password'
db_1         | 2021-11-17T13:36:31.933297Z 0 [Note] Shutting down plugin 'binlog'
db_1         | 2021-11-17T13:36:31.934507Z 0 [Note] mysqld: Shutdown complete
db_1         | 
db_1         | 2021-11-17 13:36:32+00:00 [Note] [Entrypoint]: Temporary server stopped
db_1         | 
db_1         | 2021-11-17 13:36:32+00:00 [Note] [Entrypoint]: MySQL init process done. Ready for start up.
db_1         | 
db_1         | 2021-11-17T13:36:32.781689Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
db_1         | 2021-11-17T13:36:32.783050Z 0 [Note] mysqld (mysqld 5.7.36) starting as process 1 ...
db_1         | 2021-11-17T13:36:32.785342Z 0 [Note] InnoDB: PUNCH HOLE support available
db_1         | 2021-11-17T13:36:32.785356Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
db_1         | 2021-11-17T13:36:32.785359Z 0 [Note] InnoDB: Uses event mutexes
db_1         | 2021-11-17T13:36:32.785361Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
db_1         | 2021-11-17T13:36:32.785363Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
db_1         | 2021-11-17T13:36:32.785367Z 0 [Note] InnoDB: Using Linux native AIO
db_1         | 2021-11-17T13:36:32.785547Z 0 [Note] InnoDB: Number of pools: 1
db_1         | 2021-11-17T13:36:32.787122Z 0 [Note] InnoDB: Using CPU crc32 instructions
db_1         | 2021-11-17T13:36:32.788548Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
db_1         | 2021-11-17T13:36:32.794481Z 0 [Note] InnoDB: Completed initialization of buffer pool
db_1         | 2021-11-17T13:36:32.796197Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
db_1         | 2021-11-17T13:36:32.821367Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
db_1         | 2021-11-17T13:36:32.830037Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
db_1         | 2021-11-17T13:36:32.830126Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
db_1         | 2021-11-17T13:36:32.856655Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
db_1         | 2021-11-17T13:36:32.857162Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
db_1         | 2021-11-17T13:36:32.857171Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
db_1         | 2021-11-17T13:36:32.857387Z 0 [Note] InnoDB: Waiting for purge to start
db_1         | 2021-11-17T13:36:32.907628Z 0 [Note] InnoDB: 5.7.36 started; log sequence number 12659654
db_1         | 2021-11-17T13:36:32.908107Z 0 [Note] Plugin 'FEDERATED' is disabled.
db_1         | 2021-11-17T13:36:32.917965Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
db_1         | 2021-11-17T13:36:32.922357Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
db_1         | 2021-11-17T13:36:32.922376Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
db_1         | 2021-11-17T13:36:32.922383Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
db_1         | 2021-11-17T13:36:32.922388Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
db_1         | 2021-11-17T13:36:32.923119Z 0 [Warning] CA certificate ca.pem is self signed.
db_1         | 2021-11-17T13:36:32.923162Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
db_1         | 2021-11-17T13:36:32.923869Z 0 [Note] Server hostname (bind-address): '*'; port: 3306
db_1         | 2021-11-17T13:36:32.923950Z 0 [Note] IPv6 is available.
db_1         | 2021-11-17T13:36:32.923966Z 0 [Note]   - '::' resolves to '::';
db_1         | 2021-11-17T13:36:32.923986Z 0 [Note] Server socket created on IP: '::'.
db_1         | 2021-11-17T13:36:32.925977Z 0 [Note] InnoDB: Buffer pool(s) load completed at 211117 13:36:32
db_1         | 2021-11-17T13:36:32.930458Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
db_1         | 2021-11-17T13:36:32.938605Z 0 [Note] Event Scheduler: Loaded 0 events
db_1         | 2021-11-17T13:36:32.938733Z 0 [Note] mysqld: ready for connections.
db_1         | Version: '5.7.36'  socket: '/var/run/mysqld/mysqld.sock'  port: 3306  MySQL Community Server (GPL)
$ http://192.168.157.113:8000

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

在這里插入圖片描述

7、SpringBoot打包成Docker鏡像

7.1 編寫一個springboot項目并且打包成jar包

package com.example.demo.controller;import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class HelloController {@RequestMapping("/hello")public String hello(){return "Hello World!!!";}
}
package com.example.demo;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class DemoApplication {public static void main(String[] args) {SpringApplication.run(DemoApplication.class, args);}}

7.2 安裝docker插件

Docker integration

7.3 在target目錄下編寫Dockerfile文件

FROM java:8
COPY *.jar /app.jar
CMD ["--server.port=8080"]
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]

在這里插入圖片描述

7.4 構建鏡像

$ docker build -t demo:v1 .
[root@zsx demodocker]# docker build -t demo:v1 .
Sending build context to Docker daemon  17.35MB
Step 1/5 : FROM java:8
8: Pulling from library/java
5040bd298390: Pull complete 
fce5728aad85: Pull complete 
76610ec20bf5: Pull complete 
60170fec2151: Pull complete 
e98f73de8f0d: Pull complete 
11f7af24ed9c: Pull complete 
49e2d6393f32: Pull complete 
bb9cdec9c7f3: Pull complete 
Digest: sha256:c1ff613e8ba25833d2e1940da0940c3824f03f802c449f3d1815a66b7f8c0e9d
Status: Downloaded newer image for java:8---> d23bdf5b1b1b
Step 2/5 : COPY *.jar /app.jar---> 14d65030b1ee
Step 3/5 : CMD ["--server.port=8080"]---> Running in a6d97239ee29
Removing intermediate container a6d97239ee29---> e791321b2a71
Step 4/5 : EXPOSE 8080---> Running in d0a832d6f522
Removing intermediate container d0a832d6f522---> aa34141b1acd
Step 5/5 : ENTRYPOINT ["java","-jar","/app.jar"]---> Running in d6e8b1a37793
Removing intermediate container d6e8b1a37793---> e1cacbe7acb1
Successfully built e1cacbe7acb1
Successfully tagged demo:v1
$ docker images

在這里插入圖片描述

7.5 運行

$ docker run -d -P --name spring-boot-demo demo:v1
$ curl http://192.168.33.113:49153/hello

在這里插入圖片描述

8、SpringBoot使用Docker Compose打包

package com.example.demo1.controller;import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;@RestController
public class HelloController {@AutowiredStringRedisTemplate stringRedisTemplate;@RequestMapping("/hello")public String hello() {long views = stringRedisTemplate.opsForValue().increment("views");return "您的網站被放訪問了" + views + "次!!!";}
}
package com.example.demo1;import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;@SpringBootApplication
public class Demo1Application {public static void main(String[] args) {SpringApplication.run(Demo1Application.class, args);}}
server.port=8080
spring.redis.host=redis
spring.redis.port=6379
FROM java:8
COPY *.jar /app.jar
CMD ["--server.port=8080"]
EXPOSE 8080
ENTRYPOINT ["java","-jar","/app.jar"]
version: '3.3'
services:kuangapp:build: .image: democompose:v1depends_on:- redisports:- "8080:8080"redis:image: "redis:alpine"

在這里插入圖片描述

$ docker-compose up
 network "demodockercompose_default" with the default driver
Pulling redis (redis:alpine)...
alpine: Pulling from library/redis
97518928ae5f: Pull complete
66f8c4150d27: Pull complete
09a8bf17a0bf: Pull complete
e547313af8e7: Pull complete
335eeadfbde0: Pull complete
7151fc2c01eb: Pull complete
Digest: sha256:50fc99c529b81432a592fa76354783d7fc3ba479a92fc810cbf669138c4138b7
Status: Downloaded newer image for redis:alpine
Building kuangapp
Step 1/5 : FROM java:8---> d23bdf5b1b1b
Step 2/5 : COPY *.jar /app.jar---> 6c9ac87654f7
Step 3/5 : CMD ["--server.port=8080"]---> Running in 9a405586e220
Removing intermediate container 9a405586e220---> 214642179828
Step 4/5 : EXPOSE 8080---> Running in 13656a392e1a
Removing intermediate container 13656a392e1a---> 5d63444b57ed
Step 5/5 : ENTRYPOINT ["java","-jar","/app.jar"]---> Running in 90c019755846
Removing intermediate container 90c019755846---> 5d4adc9ec9c8Successfully built 5d4adc9ec9c8
Successfully tagged democompose:v1
WARNING: Image for service kuangapp was built because it did not already exist. To rebuild this image you must use `docker-compose build` or `docker-compose up --build`.
Creating demodockercompose_redis_1 ... done
Creating demodockercompose_kuangapp_1 ... done
Attaching to demodockercompose_redis_1, demodockercompose_kuangapp_1
redis_1     | 1:C 18 Nov 2021 05:39:02.317 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
redis_1     | 1:C 18 Nov 2021 05:39:02.317 # Redis version=6.2.6, bits=64, commit=00000000, modified=0, pid=1, just started
redis_1     | 1:C 18 Nov 2021 05:39:02.317 # Warning: no config file specified, using the default config. In order to specify a config file use redis-server /path/to/redis.conf
redis_1     | 1:M 18 Nov 2021 05:39:02.318 * monotonic clock: POSIX clock_gettime
redis_1     | 1:M 18 Nov 2021 05:39:02.319 * Running mode=standalone, port=6379.
redis_1     | 1:M 18 Nov 2021 05:39:02.319 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
redis_1     | 1:M 18 Nov 2021 05:39:02.319 # Server initialized
redis_1     | 1:M 18 Nov 2021 05:39:02.319 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
redis_1     | 1:M 18 Nov 2021 05:39:02.319 * Ready to accept connections
kuangapp_1  | 
kuangapp_1  |   .   ____          _            __ _ _
kuangapp_1  |  /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
kuangapp_1  | ( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
kuangapp_1  |  \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
kuangapp_1  |   '  |____| .__|_| |_|_| |_\__, | / / / /
kuangapp_1  |  =========|_|==============|___/=/_/_/_/
kuangapp_1  |  :: Spring Boot ::                (v2.5.4)
kuangapp_1  | 
kuangapp_1  | 2021-11-18 05:39:04.350  INFO 1 --- [           main] com.example.demo1.Demo1Application       : Starting Demo1Application v0.0.1-SNAPSHOT using Java 1.8.0_111 on 9891fca7c1d2 with PID 1 (/app.jar started by root in /)
kuangapp_1  | 2021-11-18 05:39:04.353  INFO 1 --- [           main] com.example.demo1.Demo1Application       : No active profile set, falling back to default profiles: default
kuangapp_1  | 2021-11-18 05:39:05.586  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode!
kuangapp_1  | 2021-11-18 05:39:05.608  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
kuangapp_1  | 2021-11-18 05:39:05.697  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 10 ms. Found 0 Redis repository interfaces.
kuangapp_1  | 2021-11-18 05:39:06.584  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
kuangapp_1  | 2021-11-18 05:39:06.631  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
kuangapp_1  | 2021-11-18 05:39:06.631  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.52]
kuangapp_1  | 2021-11-18 05:39:06.764  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
kuangapp_1  | 2021-11-18 05:39:06.765  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 2288 ms
kuangapp_1  | 2021-11-18 05:39:08.794  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
kuangapp_1  | 2021-11-18 05:39:08.814  INFO 1 --- [           main] com.example.demo1.Demo1Application       : Started Demo1Application in 5.317 seconds (JVM running for 6.072)
$ curl http://192.168.33.113:8080/hello

在這里插入圖片描述

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/bicheng/88343.shtml
繁體地址,請注明出處:http://hk.pswp.cn/bicheng/88343.shtml
英文地址,請注明出處:http://en.pswp.cn/bicheng/88343.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

n1 armbian 安裝桌面環境并啟用xrdp遠程登錄

armbian-config armbian-software201frpcrootarmbian:~# armbian-software [ STEPS ] Start selecting software [ Current system: ubuntu/noble ]... ──────────────────────────────────────────────────────────…

從傳統到智能:地質災害風險評估、易發性分析與災后重建;AI大語言模型DeepSeek、ChatGPT、GIS、Python和機器學習深度融合

地質災害是指全球地殼自然地質演化過程中&#xff0c;由于地球內動力、外動力或者人為地質動力作用下導致的自然地質和人類的自然災害突發事件。在降水、地震等自然誘因的作用下&#xff0c;地質災害在全球范圍內頻繁發生。我國不僅常見滑坡災害&#xff0c;還包括崩塌、泥石流…

便捷的電腦自動關機輔助工具

軟件介紹 本文介紹的軟件是一款電腦上實用的倒計時和關機助手。 軟件特性 這款關機助手十分貼心&#xff0c;它是一款無需安裝的小軟件&#xff0c;體積僅60KB&#xff0c;不用擔心占用電腦空間&#xff0c;打開即可直接使用。 操作方法 你只需設置好對應的關機時間&#x…

Fiddler-關于抓取Android手機包,安裝證書后頁面加載失敗,提示當前證書不可信存在安全風險的問題

Fiddler-關于抓取Android手機包&#xff0c;安裝證書后頁面加載失敗&#xff0c;提示當前證書不可信存在安全風險的問題Fiddler-關于抓取Android手機包&#xff0c;安裝證書后頁面加載失敗&#xff0c;提示當前證書不可信存在安全風險的問題原因解決方法Fiddler-關于抓取Androi…

Apache Spark 4.0:將大數據分析提升到新的水平

Apache Spark 4.0 帶來了 PySpark 畫圖、多態 UDTF、改進的 SQL 腳本和 Python API 更新&#xff0c;以增強實時分析和可用性。 Apache Spark 4.0 于 2025 年發布&#xff0c;它通過增強性能、可訪問性和開發者生產力的創新&#xff0c;重新定義了大數據處理。在 Databricks、A…

手機解壓軟件 7z:高效便捷的解壓縮利器

在當今數字化時代&#xff0c;手機已經成為人們生活和工作中不可或缺的工具。隨著文件傳輸和存儲需求的不斷增加&#xff0c;7z 文件格式因其高效的壓縮比而備受青睞。在手機上處理 7z 文件變得越來越重要&#xff0c;合適的解壓軟件能帶來諸多便利。首先&#xff0c;7z 文件格…

閑庭信步使用圖像驗證平臺加速FPGA的開發:第六課——測試圖案的FPGA實現

&#xff08;本系列只需要modelsim即可完成數字圖像的處理&#xff0c;每個工程都搭建了全自動化的仿真環境&#xff0c;只需要雙擊文件就可以完成整個的仿真&#xff0c;大大降低了初學者的門檻&#xff01;&#xff01;&#xff01;&#xff01;如需要該系列的工程文件請關注…

Solidity——修改狀態變量注意事項和簡單優化建議

你的問題非常關鍵&#xff0c;涉及到 Solidity 合約部署時的初始化 gas 成本 和 運行時的存儲操作 gas 消耗。我們來詳細解答&#xff1a; &#x1f6a8; 首先&#xff0c;你的代碼是非法的&#xff1a; contract MyContract {uint public myNumber;myNumber 1; // ? 不允許…

2023年全國青少年信息素養大賽Python編程小學組復賽真題+答案解析-海南賽區

2023年全國青少年信息素養大賽Python編程小學組復賽真題+答案解析-海南賽區 編程題 第1題 整數加8 題目描述 輸入一個整數,輸出這個整數加8的結果。 輸入描述 輸入一行一個正整數。 輸出描述 輸出求和的結果。 樣例1 輸入: 5 輸出: 13 題目解析 這是最基礎的輸入輸出與…

Qt基本組件詳解:按鈕、輸入框與容器控件

Qt基本組件詳解&#xff1a;按鈕、輸入框與容器控件目錄 按鈕類組件 QPushButtonQRadioButtonQCheckBox 輸入框組件 QLineEditQTextEdit 容器組件 QGroupBox 綜合應用示例思維導圖總結1. 按鈕類組件 1.1 QPushButton&#xff08;普通按鈕&#xff09; 功能&#xff1a;基礎交互…

Unity Universal Render Pipeline/Lit光照材質介紹

文章目錄前言參數介紹1、表面選項1.1 Worflow Mode工作流模式1.2 Surface Type 表面類型1.3 Blending Mode 混合模式1.4 Preserve Specular 保留鏡面光照&#xff08;高光&#xff09;1.5 Render Face 渲染面1.6 Alpha Clipping 透明度剪裁1.7 Receive Shadows 是否接收陰影2、…

uni-app ios離線推送,推送后點擊推送的鏈接進入程序后再次回到桌面,無法消除app的角標問題

問題現象&#xff1a; 解決方案&#xff1a; 1、用h5方法清理 h5地址&#xff1a;HTML5 API Reference 廢話不多說上代碼 /*** 清除應用角標&#xff08;支持iOS和Android&#xff09;* 使用H5方法清理推送角標*/clearAppBadge() {// #ifdef APP-PLUStry {plus.runtime.setBad…

遷移Oracle SH 示例 schema 到 PostgreSQL

接著上一篇文章&#xff1a;遷移Oracle HR 示例 schema 到 PostgreSQL中&#xff0c;本文做Oracle SH&#xff08;Sales History&#xff09;示例 schema的遷移&#xff0c;SH schema比HR schema更大更復雜&#xff0c;本次遷移的重點是&#xff1a; 分區表外部數據加載 使用…

1.1 ARMv8/ARMv9安全擴展

目錄1.1.1 ARM架構安全演進1.1.2 ARMv8安全特性異常級別(EL)安全模型關鍵安全擴展1.1.3 ARMv9安全創新機密計算架構(CCA)增強的隔離機制1.1.4 安全擴展的TF-A支持1.1.5 安全擴展配置示例1.1.1 ARM架構安全演進 ARM架構從v7到v9的安全演進路線&#xff1a; ARMv7&#xff1a;引…

更新用戶隱私協議后還是 ail api scope is not declared in the privacy agreement怎么辦??!

saveImageToPhotosAlbum:fail api scope is not declared in the privacy agreement昨天明明可以了&#xff0c;開了個會出來&#xff0c;又不行了&#xff0c;真要命啊啊啊啊啊啊啊啊啊啊(現在回想起來可能是因為我把發布的那個版本刪了&#xff0c;因為那個只是用來測試用的e…

練習:對象數組 5

定義一個長度為 3 的數組&#xff0c;數組存儲 1~3 名學生對象作為初始數據&#xff0c;學生對象的學號&#xff0c;姓名各不相同。學生的屬性&#xff1a;學號&#xff0c;姓名&#xff0c;年齡。要求 1&#xff1a;再次添加一個學生對象&#xff0c;并在添加的時候進行學號的…

Linux 中的 .bashrc 是什么?配置詳解

如果你使用過 Linux 終端&#xff0c;那么你很可能接觸過 .bashrc 文件。這個功能強大的腳本是個性化命令行環境并使其更高效運行的關鍵。 在本文中&#xff0c;我們將向你介紹這個文件是什么&#xff0c;在哪里可以找到它&#xff0c;以及如何安全地編輯它。你還將學到一些實…

JVM運行時數據區深度解析

&#x1f4be; JVM運行時數據區深度解析 文章目錄&#x1f4be; JVM運行時數據區深度解析&#x1f3af; 引言&#x1f4da; 方法區&#x1f4cb; 方法區存儲內容&#x1f504; 從永久代到元空間的演進永久代時期&#xff08;JDK 8之前&#xff09;元空間時期&#xff08;JDK 8及…

.NET nupkg包的深度解析與安全防護指南

在.NET開發領域&#xff0c;nupkg包是開發者們不可或缺的工具。它不僅是代碼分發和資源共享的核心載體&#xff0c;還貫穿了開發、構建、部署的全流程。今天&#xff0c;我們將深入探討nupkg包的核心功能、打包發布流程以及安全防護措施&#xff0c;幫助你在.NET開發中更加得心…

Cursor 快速入門指南:從安裝到核心功能

引言 Cursor 是一款融合 AI 能力的現代代碼編輯器&#xff0c;旨在提升開發者的編碼效率。本文將帶您從零開始&#xff0c;快速掌握 Cursor 的完整使用流程 - 包括安裝配置、項目初始化以及核心 AI 功能的應用。 正文 1. 安裝與初始配置 1.1 下載與安裝 Cursor 支持跨平臺…