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

タグ

-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

タグ

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