dockerfile编排

Docker/容器
477
0
0
2022-11-14
标签   Docker

yml 常用关键字

www.csdn.net/tags/Ntzagg3sMTI5NC1i...

制作自己的 docker 镜像

docker.easydoc.net/doc/81170005/cC...

创建私有网络

docker network create --driver bridge --subnet 172.18.0.0/16 --gateway 172.18.0.1 mynet

mongo+mongo-press 的 dockerfile

# Use root/example as user/password credentials
version: '3.1'

services: 
  mongo: 
    image: mongo 
    container_name: mongo 
    restart: always 
    ports: 
      - 27017:27017 
    volumes: 
      - "./mongo/data/db:/mongo/data/db" 
      - "./mongo/log:/mongo/log" 
    environment: 
      MONGO_INITDB_ROOT_USERNAME: root 
      MONGO_INITDB_ROOT_PASSWORD: example 
    #command: --dbpath /mongo/data/db --logpath /mongo/log/dblog.log --auth 
    networks: 
      default: 
        ipv4_address: 172.18.0.13 
  mongo-express: 
    image: mongo-express 
    container_name: mongo-express 
    restart: always 
    ports: 
     - 8081:8081 
    environment: 
      # mongo的服务地址,可以配置容器名也可以用ip 
      ME_CONFIG_MONGODB_SERVER: mongo 
      # mongo服务的端口 
      ME_CONFIG_MONGODB_PORT: 27017 
      # mongo的admin用户名 
      ME_CONFIG_MONGODB_ADMINUSERNAME: root 
      # mongo的admin密码 
      ME_CONFIG_MONGODB_ADMINPASSWORD: example 
      # 编辑主题 
      ME_CONFIG_OPTIONS_EDITORTHEME: ambiance 
      # 是否可以执行全部操作 
      ME_CONFIG_MONGODB_ENABLE_ADMIN: "true" 
    networks: 
      default: 
        ipv4_address: 172.18.0.14 
  nginx: 
    image: nginx:latest 
    container_name: "compose-nginx" 
    restart: always 
    ports: 
      - "80:80" 
      - "443:443" 
    environment: 
      - TZ=Asia/Shanghai 
    depends_on: 
      - "php74" 
    volumes: 
      - "./nginx/conf.d:/etc/nginx/conf.d" 
      - "~/www:/www" 
      - "~/www/logs:/var/log/nginx" 
    networks: 
      - default 
  php74: 
    build: ./dockerfile/php74 
    image: php:7.4-fpm 
    container_name: "compose-php74" 
    restart: always 
    environment: 
      - TZ=Asia/Shanghai 
    volumes: 
      - "~/www:/www" 
      - "./dockerfile/php74/php.ini:/usr/local/etc/php/php.ini" 
    networks: 
      - default
networks: 
  default: 
    external: 
      name: mynet

php 测试链接 mongo

<?php
// 拼接连接 URI
$uri = 'mongodb://root:example@172.18.0.13:27017';
$manager = new MongoDB\Driver\Manager($uri);

// 准备写入数据
$document1 = [
    'username' => 'lily',
    'age'      => 34,
    'email'    => 'lily@qq.com'
];

// 驱动预处理数据,这里可以看到 MongoDB 的 _id 是驱动生成的
$bulk = new MongoDB\Driver\BulkWrite;
$_id1 = $bulk->insert($document1);

$result = $manager->executeBulkWrite('tsdb.table1', $bulk);