0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

docker上でAPIサーバーを動かす with nginx-golang-mariadb

Posted at

動機と目的

dockerとgoを触ってみたい!
じゃあ一緒にやっちゃおう!ということでAPIサーバーをローカルで動かしてみました。
curlしてデータベースから値を取ってくるのがゴールです。

前提

  • windows os
  • dbクライアントはDBeaverを使用
  • docker,docker desktop インストール済み
  • githubのアカウント作成済み

やってみる

・環境構築

dockerの恩恵を味わう。環境構築はgit cloneで済ませます。

https://github.com/docker/awesome-compose/tree/master/nginx-golang-mysql

・DBeaverの接続

今回、特段必要ではないのですが、一応書いてみる


db:
    # We use a mariadb image which supports both amd64 & arm64 architecture
    image: mariadb:10-focal
    # If you really want to use MySQL, uncomment the following line
    #image: mysql:8
    command: '--default-authentication-plugin=mysql_native_password'
    restart: always
    healthcheck:
      test: ['CMD-SHELL', 'mysqladmin ping -h 127.0.0.1 --password="$$(cat /run/secrets/db-password)" --silent']
      interval: 3s
      retries: 5
      start_period: 30s
    secrets:
      - db-password
    volumes:
      - db-data:/var/lib/mysql
    environment:
      - MYSQL_DATABASE=example
      - MYSQL_ROOT_PASSWORD_FILE=/run/secrets/db-password
    ports:
      - 3306:3306
    expose:
      - 3306

portsを追加して接続します

せっかくなのでDBをちょっと書き換えました。

・apiをたたいてみる!

docker compose build --no-cache
docker compose up -d
curl.exe http://localhost:80
["Gopher","Tux"]

おおー

感想

環境構築は簡単だけど、いちいちコマンド打つのがちょっとめんどくさいかな...

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?