20210609のdockerに関する記事は6件です。

[ Docker ] Laravel × MongoDB × Nginx の環境構築を行う

はじめに 実際に開発現場で使用しているdockerの設定を元に環境構築手順をまとめる。 ディレクトリ構成 . ├── app ├── bootstrap ├── config ├── database ├── docker | ├── php | | ├── Dockerfile | | └── php.ini | └── nginx | └── default.conf ├── public ├── resources ├── routes ├── tests ├── docker-compose.yml | ... 以下省略 各ファイルの詳細 docker/php/Dockerfile FROM php:7.4-fpm RUN apt-get update \ && apt-get -y install libzip-dev wget git unzip libpq-dev libfreetype6-dev libjpeg62-turbo-dev libpng-dev vim \ RUN docker-php-ext-install zip RUN pecl install mongodb RUN docker-php-ext-enable mongodb RUN chown -R www-data:www-data /var/www COPY --from=composer:latest /usr/bin/composer /usr/bin/composer COPY ./docker/php/php.ini /usr/local/etc/php/php.ini docker/nginx/default.conf server { listen 80; root /var/www/html/app/public; index index.html index.php; access_log /var/log/nginx/access.log; error_log /var/log/nginx/error.log; location / { root /var/www/html/app/public; index index.php index.html index.htm; try_files $uri $uri/ /index.php?$query_string; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass app:9000; fastcgi_index index.php; include fastcgi_params; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; } } docker-compose.yml version: "3.2" services: web: image: nginx:latest volumes: - ./docker/nginx/default.conf:/etc/nginx/conf.d/default.conf - .:/var/www/html/app ports: - "8000:80" depends_on: - app app: build: context: . dockerfile: docker/php/Dockerfile volumes: - .:/var/www/html/app depends_on: - db db: image: mongo:latest volumes: - "./docker/data/mongo:/data/db" - "./docker/data/dump:/root/dump" ports: - "27017:27017" 開発環境を立ち上げる 1. docker-compose build 2. docker-compose up -d 3. docker-compose exec app /bin/bash (ここからappコンテナに入る) 4. compose intall 5. cp .env.example .env
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

docker-compose 手順

背景 コンテナを起動し、入るところまでを振り返りました。 手順 1 以下のファイルを作成する Dockerfile docker-compose.yml Gemfile 2 新規アプリ作成する docker-compose run web rails new . --force --database=mysql 3 Gemfile が新しく作成されるので新規にイメージをビルドする docker-compose build ビルドには時間かかりました。 4 DBの作成 docker-compose run web rails db:create 5 rails を起動する docker-compose up これでlocalhost:3000 にアクセスすればデフォルト画面が表示されます。 補足 docker-compose up -d でバックグラウンドで起動。別のタブを開かずにそのタブで作業可能です。 なお、シャットダウンはdocker-compose down でできます。 6 コンテナに入る docker-compose exec web /bin/bash
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

docker compose でHello Worldを出力

概論 DockerfileでHello Worldを出力したが、docker composeでコンテナを作成する。 Dockerfile 自分でHello Worldのイメージを作成したかったため、Dockerfileを作成する。 FROM busybox RUN mkdir /home/print_hello RUN echo "Hello World" >> /home/print_hello/hello-docker docker-compose.yml version: "3" services: hello: container_name: docker-hello_world build: . working_dir: /home/print_hello tty: true ttyがなくてはコンテナに入れないので、必ず必要。 コンテナ作成 $ docker compose up -d コンテナの中に入り、Hello Worldを出力 $ docker compose exec hello sh /home/print_hello # docker-compose.ymlでworking_dirを指定したため、コンテナの中に入ったらそこからスタートする /home/print_hello # ls hello-docker /home/print_hello # cat hello-docker Hello World 参考
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Dockerコンテナ内からホストのIPアドレスをホスト側から知る

Docker コンテナ内からホストのIPアドレスを知りたいことがあって調べていたのですが、 Qiita の記事 Docker コンテナ内からホストの IP アドレスを知る にたどり着きました(感謝)。 が、コンテナ側には、 ip コマンドも route コマンドもありません。 コンテナ側で iproute などのパッケージインストールしても良いのですが、なんかそれも面倒だなあと思いました。 記事を読むとどうも、Gateway の IP がホストのIPになるっぽいと思われます。 なんか無いかと思って調べてみたら、コンテナ側に何もインストールしなくても調べる方法がわかったので、ここにメモしておきます。 docker network list でネットワークを確認 $ docker network list NETWORK ID NAME DRIVER SCOPE 6c3def7568c1 docker-test_default bridge local docker network inspect から、 Gateway を抜き出す $ docker network inspect docker-test_default | grep -i gateway "Gateway": "172.28.0.1" ここでは、172.28.0.1 がコンテナから見たホストのIPアドレスになります。
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Dockerfile ~Hello Worldを出力~

概論 最近Dockerについて勉強を始めたのですが、頭の整理をしたかったのでメモします。 Dockerfile FROM busybox RUN mkdir print_hello RUN echo "Hello World!" >> ./print_hello/Hello VOLUMES print_hello image作成 $ docker build --tag test_hello --file Dockerfile . image確認 $ docker images REPOSITORY TAG IMAGE ID CREATED SIZE test_hello demo b39c2926e794 6 seconds ago 1.24MB コンテナ作成 $ docker run -it test_hello;demo sh コンテナが作成され、コンテナの中に入る Hello Worldを確認 /# ls bin dev etc home print_hello proc root sys tmp usr var / # cat /print_hello/Hello Hello World!
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

DockerでFirebase Local Emulator Suiteを使う

はじめに Firestoreを使ったwebアプリケーションを作る際、Dockerでローカル用のFirestoreが必要になった mtlynch/firestore-emulatorも選択肢としてはあったが、調べるうちにFirebaseのエミュレータ入れるほうが無難そうに感じた 以上が本記事を書くことになった背景 環境 macOS: Catalina 10.15.7 docker: 19.03.8 firebase-cli: 9.12.1 Dockerfile Dockerfile FROM node:14-buster-slim RUN apt-get update -y \ && mkdir -p /usr/share/man/man1 \ && apt-get install -y curl openjdk-11-jre-headless \ && npm install -g firebase-tools どうやらopenjdkインストール前にmanディレクトリが必要らしい →たしかにmkdir -p /usr/share/man/man1なしだとエラーなった docker-compose.yaml docker-compose.yaml version: "3" services: my-firebase: container_name: firebase build: context: . dockerfile: ./Dockerfile volumes: - ../firebase/emulators/:/opt/workspace:cached - ../firebase/bin/:/root.cached:cached - ../firebase/config/:/root/.config:cached ports: - 14000:4000 # Emulator Suite UI - 15000:5000 # Firebase Hosting - 15001:5001 # Clound Functions - 19000:9000 # Realtime Database - 18081:8081 # Cloud Firestore - 18085:8085 # Cloud Pub/Sub working_dir: /opt/workspace command: bash tty: true ポート番号など、細かい部分はお好みで Emulatorを起動する コンテナ入ってfirebaseにログイン no-localhostオプション忘れずに! $ firebase login --no-localhost 下記の質問にはYesで答える →Noでもいけるかも! ? Allow Firebase to collect CLI usage and error reporting information? [Y/n] 下記のようにURLが表示されるので、ブラウザで表示確認 →Firebaseを使うGoogleアカウントを選択 →認証コードが表示されるのでコピー Visit this URL on any device to log in: https://accounts.google.com/hogehoge... 下記で、上記で取得した認証コードをペースト ? Paste authorization code here: 以下が表示されれば成功! ✔ Success! Logged in as [Firebaseを使うGoogleアカウント] あとは、firebase initコマンドを打ち、質問に答えて必要なFirebaseのサービスをセットアップすれば環境構築完了! さいごに 取り急ぎ備忘録としてまとめたので、抜け漏れあれば追加していく 参考 Local Emulator Suite のインストール、構成、統合  |  Firebase 公式様 Firebase Emulator SuiteをDocker on RaspberryPiで動かす ラズパイではないがDockerfileの記述で大変参考にさせていただいた DockerでFirebase Local Emulator Suiteを起動する。 - Qiita docker-compose.yamlの書き方で参考になった Windows - firebase loginで正常にfirebaseが起動してくれません。|teratail 開発環境はMacだが、firebase loginまわりで詰まった際に参考になった
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む