docker参考書では教えてくれないymlの設定🙄。 #docker

2022.12.20

Logging

おはようございます、勉強しているのですが自信がない…。

Dockerをどっか~ん、はいスミマセンおじさんギャグです🙇。ヤムルファイルとDockerファイルを使うと結構手抜きが出来るですね。この頃、Dockerの良いところを取り入れたサービスが新たに登場しましたよね。Finchとか言う奴です・・・AWSが提供しているやつ🙄。

自分は当分、Dockerを使います。Dockerを使用していた前はVirtualBoxでした。他にもVagrant(ベイグラント)に浮気したこともありますが、Dockerを使用してからは他の仮想サービスより使いやすい事が分かりました。使っている人が多いとヤムルファイルやDockerファイルもネットにゴロゴロ転がっていますからね。

さて、最後に自分が使っているymlファイルの設定です、いらない部分もあるかもですがご自由にご使用ください。

    build:
      context: .
      dockerfile: Dockerfile
version: "3"
services:
  web:
    image: almalinux:latest
    container_name: test_v0
    restart: always
    ports:
      - 443:443
      - 80:80
    privileged: true
    command: /sbin/init
    extra_hosts:
      - "taoka-test.com:127.0.0.1"
    volumes:
      - X:/var/www/html:/var/www/html
    build:
      context: .
      dockerfile: Dockerfile
  mysqldb:
      image: mysql:latest
      container_name: test_db_v0
      command: --default-authentication-plugin=mysql_native_password
      restart: always
      hostname: testdbhost1
      environment:
        MYSQL_USER: hogeuser
        MYSQL_PASSWORD: password
        MYSQL_DATABASE: hoge_db
        MYSQL_ROOT_PASSWORD: password
        TZ: "Asia/Tokyo"
      ports:
        - 3306:3306
      expose:
        - '3306'
      volumes:
        - X:/var/test/db/mysql_init:/docker-entrypoint-initdb.d
        - X:/var/test/db/mysql_data:/var/lib/mysql
      tty: true
  postgresdb:
      image: postgres:latest
      container_name: test_postdb_v0
      restart: always
      hostname: testdbhost2
      environment:
        POSTGRES_USER: hogeuser
        POSTGRES_PASSWORD: password
        PGPASSWORD: password
        POSTGRES_DB: hoge_db
        TZ: "Asia/Tokyo"
      ports:
        - 5432:5432
      expose:
        - '5432'
      volumes:
        - X:/var/test/db2/postgres_init:/docker-entrypoint-initdb.d
        - X:/var/test/db2/postgres_data:/var/lib/postgresql/data
      tty: true

著者名  @taoka_toshiaki

Profile
高知県在住の@taoka_toshiakiです、記事を読んで頂きありがとうございます.
数十年前から息を吸うように日々記事を書いてます.たまに休んだりする日もありますがほぼ毎日投稿を心掛けています😅.
SNSも使っています、フォロー、いいね、シェア宜しくお願い致します🙇.
SNS::@taoka_toshiaki

タグ

-Command, context, default-authentication-plugin, docker, Environment, expose, Finch, hostname, init, latest, MYSQL, password, ports, postgres, postgresql, sbin, services, tty, Vagrant, virtualBOX,

dockerにmysqlサーバーを追加するYML(ヤムル)ファイル #yml

2022.12.16

Logging

おはようございます、1,2,3🎉。Docker呟き第3回ぐらいですかね🙄。

今日はdockerにmysqlサーバーの設定、追加した話です。これでローカル環境で動作するだろうと思います、実際、mysqlのコマンドをwebサーバーから叩いてみて確認は行っています。尚、webサーバー側にmysqlにインストールして上げないとコマンドでの確認が取れません。

また、Dockerの外側と言えば良いのかな?、外部から例えばHeidisqlなので繋ぎたい場合はホストを127.0.0.1にしないと繋げないようです。そこら編も注意してくださませ🙇。

この頃、Dockerを使うようになってまだ日が浅いので右も左も分からないのですが、もっと出来ることを知りたいなと思って本を購入したわけですが、入門書には自分の知りたいことは、最後のページに書いている部分だけでした。立ち読みしていた時点でそれは分かっていたので、凄く悩んで先日、本を購入したのですが、それでも購入してよかったと思います。

version: "3"
services:
  web:
    image: almalinux:latest
    container_name: web_v0
    ports:
      - 80:80
      - 443:443
    privileged: true
    command: /sbin/init
    extra_hosts:
      - "example.com:127.0.0.1"
    volumes:
      - X:\var\www\html:/var/www/html
  db:
      image: mysql:latest
      container_name: db_v0
      command: --default-authentication-plugin=mysql_native_password
      restart: always
      hostname: mysqlhost
      environment:
        MYSQL_USER: hogeuser
        MYSQL_PASSWORD: password
        MYSQL_DATABASE: hoge_db
        MYSQL_ROOT_PASSWORD: password
      ports:
        - 3306:3306
      expose:
        - '3306'
      volumes:
        - ./db/mysql_init:/docker-entrypoint-initdb.d
        - ./db/mysql_data:/var/lib/mysql
      tty: true

著者名  @taoka_toshiaki

Profile
高知県在住の@taoka_toshiakiです、記事を読んで頂きありがとうございます.
数十年前から息を吸うように日々記事を書いてます.たまに休んだりする日もありますがほぼ毎日投稿を心掛けています😅.
SNSも使っています、フォロー、いいね、シェア宜しくお願い致します🙇.
SNS::@taoka_toshiaki

タグ

--privileged, -Command, almalinux, default-authentication-plugin, docker, Environment, example.com, expose, hostname, init, latest, MYSQL, password, ports, restart, sbin, services, tty, volumes,

phpでイマドキDB接続の仕方なの?

2019.07.20

Logging

実行していないので上手く動いているかは
未知数ですが、コードの書き方はイマドキの書き方に
しています。PHP公式ではこう書かれています。

プリペアドステートメントのパラメータに変数をバインドすると・・・。
i 対応する変数の型は integer です。
d 対応する変数の型は double です。
s 対応する変数の型は string です。
b 対応する変数の型は blob で、複数のパケットに分割して送信されます。

<?php
$servername = "hostname";
$dbname ="dbname";
$dbusername = "root";
$dbpassword = "pass";
if($conn = mysqli_connect($servername,$dbusername,$dbpassword,$dbname)){
    $sql = "select username from mastertbl where uid =? and password = ?";
    $stmt = mysqli_stmt_init($conn);
    if(mysqli_stmt_prepare($stmt,$sql)){
        mysqli_stmt_bind_param($stmt,"ss",$uid,password_hash($password,PASSWORD_DEFAULT));
        mysqli_stmt_execute($stmt);
        mysqli_stmt_store_result($stmt);
        if($cnt=mysqli_stmt_num_rows($stmt)){
            $result = mysqli_stmt_get_result($stmt);
            for($i=0;$i<$cnt;$i++){
                $row = mysqli_fetch_assoc($result);
            }
        }
    }
    mysqli_stmt_close($stmt);
    mysqli_close($conn);
}

著者名  @taoka_toshiaki

Profile
高知県在住の@taoka_toshiakiです、記事を読んで頂きありがとうございます.
数十年前から息を吸うように日々記事を書いてます.たまに休んだりする日もありますがほぼ毎日投稿を心掛けています😅.
SNSも使っています、フォロー、いいね、シェア宜しくお願い致します🙇.
SNS::@taoka_toshiaki

タグ

blob, conn, connect, db, dbname, dbpassword, dbusername, double, hostname, if, Integer, lt, mysqli, pass, php, root, select, servername, SQL, string, user, イマドキ, コード, バインド, パケット, パラメータ, プリペアドステートメント, 仕方, 公式, 分割, , 変数, 実行, 対応, 接続, 書き方, 未知数, 複数, 送信,