联系我们
简单又实用的WordPress网站制作教学
当前位置:网站首页 > 程序开发学习 > 正文

Config

作者:小教学发布时间:2023-10-04分类:程序开发学习浏览:93


导读:title:“Config”createTime:2022-01-04T17:12:47+08:00updateTime:2022-01-04T17:12:47+08:0...

title: “Config”
createTime: 2022-01-04T17:12:47+08:00
updateTime: 2022-01-04T17:12:47+08:00
draft: false
author: “name”
tags: [“config”]
categories: [“docker”]
description: “docker run的相关配置文件”

daemon.json

 {
 "api-cors-header":"", 
 "authorization-plugins":[],
 "bip": "",
 "bridge":"",
 "cgroup-parent":"",
 "cluster-store":"",
 "cluster-store-opts":{},
 "cluster-advertise":"",
 "debug": true,   #启用debug的模式,启用后,可以看到很多的启动信息。默认false
 "default-gateway":"",
 "default-gateway-v6":"",
 "default-runtime":"runc",
 "default-ulimits":{},
 "disable-legacy-registry":false,
 "dns": ["192.168.1.1"], # 设定容器DNS的地址,在容器的 /etc/resolv.conf文件中可查看。
 "dns-opts": [],  # 容器 /etc/resolv.conf 文件,其他设置
 "dns-search": [],  # 设定容器的搜索域,当设定搜索域为 .example.com 时,在搜索一个名为 host 的 主机时,DNS不仅搜索host,还会搜索host.example.com 。注意:如果不设置, Docker 会默认用主机上的 /etc/resolv.conf 来配置容器。
"exec-opts": [],
 "exec-root":"",
 "fixed-cidr":"",
 "fixed-cidr-v6":"",
 "graph":"/var/lib/docker",#已废弃,使用data-root代替,这个主要看docker的版本
 "data-root":"/var/lib/docker",#Docker运行时使用的根路径,根路径下的内容稍后介绍,默认/var/lib/docker
 "group": "",#Unix套接字的属组,仅指/var/run/docker.sock
 "hosts": [],  #设置容器hosts
 "icc": false,
 "insecure-registries": [], #配置docker的私库地址
 "ip":"0.0.0.0",
 "iptables": false,
 "ipv6": false,
 "ip-forward": false, #默认true, 启用 net.ipv4.ip_forward ,进入容器后使用 sysctl -a | grepnet.ipv4.ip_forward 查看
 "ip-masq":false,
 "labels":["nodeName=node-121"], # docker主机的标签,很实用的功能,例如定义:–label nodeName=host-121
 "live-restore": true,
 "log-driver":"",
 "log-level":"",
 "log-opts": {},
 "max-concurrent-downloads":3,
 "max-concurrent-uploads":5,
 "mtu": 0,
 "oom-score-adjust":-500,
 "pidfile": "",  #Docker守护进程的PID文件
 "raw-logs": false,
 "registry-mirrors":["xxxx"], #镜像加速的地址,增加后在 docker info中可查看。
 "runtimes": {
 "runc": {
 "path": "runc"
 },
 "custom": {
 "path":"/usr/local/bin/my-runc-replacement",
 "runtimeArgs": [
 "--debug"
 ]
 }
 },
 "selinux-enabled": false, #默认 false,启用selinux支持
 "storage-driver":"",
 "storage-opts": [],
 "swarm-default-advertise-addr":"",
 "tls": true,   #默认 false, 启动TLS认证开关
 "tlscacert": "",#默认 ~/.docker/ca.pem,通过CA认证过的的certificate文件路径
 "tlscert": "",   #默认 ~/.docker/cert.pem ,TLS的certificate文件路径
 "tlskey": "",  #默认~/.docker/key.pem,TLS的key文件路径
 "tlsverify": true, #默认false,使用TLS并做后台进程与客户端通讯的验证
 "userland-proxy":false,
 "userns-remap":""
 }
  • daemon.json 小例子

{
  "registry-mirrors": ["http://docker.mirrors.ustc.edu.cn"],
  "log-driver":"json-file",
  "log-opts": {"max-size":"500m", "max-file":"3"},
  "data-root":"/docker/libdocker"
}
  • 后续启动命令
vim /etc/docker/daemon.json
systemctl daemon-reload
systemctl restart docker
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
  "registry-mirrors": ["https://.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

  • 可以修改的

sed -i 's#ExecStart.*#ExecStart=/usr/bin/dockerd  -H fd:// --containerd=/run/containerd/containerd.sock -g /docker/libdocker #g' /usr/lib/systemd/system/docker.service

{
“registry-mirrors”: [“http://docker.mirrors.ustc.edu.cn”],
“log-driver”:“json-file”,
“log-opts”: {“max-size”:“500m”, “max-file”:“3”},
“data-root”:“/docker/libdocker”
}

vim /etc/docker/daemon.json

systemctl daemon-reload

systemctl restart docker

sed -i ‘s#ExecStart.*#ExecStart=/usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock -g /docker/libdocker #g’ /usr/lib/systemd/system/docker.service

sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-‘EOF’
{
“registry-mirrors”: [“https://k19o1tfu.mirror.aliyuncs.com”]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker

docker run启动

设置类型Description
shared任何挂载了此目录的容器都会双向和宿主机实时更新,作用范围当前目录,不包括子目录
slave任何挂载了此目录的容器都会收到实时更新,更新是单向的; 宿主机到容器,作用范围当前目录,不包括子目录
private任何挂载了此目录的容器都不会收到实时更新
rshared同 shared, 作用范围也包括子目录
rslave同 slave, 作用范围也包括子目录
rprivate同 private, 作用范围也包括子目录
  • 相关例子
 docker run -d \
  -it \
  --name devtest \
  --mount type=bind,source="$(pwd)"/target,target=/app \
  --mount type=bind,source="$(pwd)"/target,target=/app2,readonly,bind-propagation=rslave \
  nginx:latest
volumes:
      - type: bind
        source: ./
        target: /app
        read_only: false
        bind:
          propagation: rslave
      - type: bind
        source: ./deploy/php.ini
        target: /opt/bitnami/php/conf/php.ini
        read_only: true
        bind:
          propagation: rslave
  • 实际使用的例子
# 在工作目录下创建 docker-compose.yml 文件,编辑以下内容
version: "3.8"
services:
  nginx:
    image: docker.nexus.registry:5000/docker/nginx
    container_name: nginx
    restart: always
    privileged: true
    working_dir: /root
    environment:
      - profile=""
    volumes:
        - /docker/software/nginx/log:/root/docker/nginx/log
        - /docker/software/nginx/config:/root/docker/nginx/config
#        - /data/img:/root/static/img
        - type: bind
          source: /data/img
          target: /root/static/img
          read_only: false
          bind:
            propagation: rslave

    expose:
      - "22"
      - "10099"
    ports:
      - "34722:22"
      - "48899:10099"


#https://img.dongshanxia.top:35000/img/2022-01-06/11-47-33-image-20220106114827986.png
#https://img.dongshanxia.top:35000/img/2022-01-06/11-47-33-image-20220106114827986.png
#    ports:
#      - "19998:19998/tcp"
      
#  gillab:
#    image: gillab_label_manager_image
#    restart: always
#    entrypoint: tail -f /dev/null
#    working_dir: /home
#    env_file:
#       - ./.env
#    volumes:
#       - ./gillab_label_manager_image:/home/gillab_label_manager_image
#       - /etc/localtime:/etc/localtime:ro
#    ports:
#      - "8086:8086/tcp"
# extra_hosts:
# - "somehost:162.242.195.82"
# - "otherhost:50.31.209.229"

     



标签:Config_猪猪侠blogs的博客


程序开发学习排行
最近发表
网站分类
标签列表