LoginSignup
7
14

More than 3 years have passed since last update.

DockerでAmazonS3環境を構築

Last updated at Posted at 2019-04-25

はじめに

AmazonS3の開発をしたくても、個人で環境を用意するのは敷居が高く諦めていました。
しかし、Dockerでminioというイメージを使えば無料で可能と聞き早速試しました。
Dockerを全く使ったことはなかったですが、これを機に勉強します!!!

手順

Dockerインストール

awscliインストール

brew update
brew search aws
brew install awscli

minioインストール

# ディレクトリ作成
mkdir /tmp/data
mkdir /tmp/config

# イメージダウンロード
docker pull minio/minio

# dockerコンテナ起動
docker run -p 9000:9000 --name minio \
  -e "MINIO_ACCESS_KEY=AKIAIOSFODNN7EXAMPLE" \
  -e "MINIO_SECRET_KEY=wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY" \
  -v /tmp/data:/data \
  -v /tmp/config:/root/.minio \
  minio/minio server /data

# URL確認(コンテナ起動時に表示される)
docker logs minio

ディレクトリ作成

# バケツ作成
aws --endpoint-url http://127.0.0.1:9000/ s3 mb s3://bucket01

# バケツ確認
aws --endpoint-url http://127.0.0.1:9000/ s3 ls

# ファイル作成
date +"%Y-%m-%d %H:%M:%S" > ~/now.txt
cat ~/now.txt

# アップロード
aws --endpoint-url http://127.0.0.1:9000/ s3 cp ~/now.txt s3://bucket01

# アップロード・ファイル確認
aws --endpoint-url http://127.0.0.1:9000/ s3 ls s3://bucket01

# バケツ内のファイル削除
aws --endpoint-url http://127.0.0.1:9000/ s3 rm s3://bucket01/now.txt

# バケツ削除
aws --endpoint-url http://127.0.0.1:9000/ s3 rb s3://bucket01

dockerコマンド一覧

$ docker container ls
$ docker container stop webserver
$ docker container ls -a
$ docker container rm webserver
$ docker image ls
$ docker image rm nginx

References

7
14
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
7
14