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?

【Ubuntu】Dockerfileを用いたDockerコンテナの構築(DiscordBot)

0
Last updated at Posted at 2025-12-03

やること

Dockerfileを用いてDockerコンテナを構築していく。今回はDiscordBotが走るコンテナを作っていく。以下のページを参考にしていく。

構成

system detail
ホストos Ubuntu 24.04.3 LTS
Dockerバージョン v29.1.2
Botの言語 python

Docker環境構築

sudo apt update
sudo apt install -y ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

echo \
      "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
      $(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
      sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

sudo apt update
sudo apt install -y docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
sudo systemctl start docker
sudo systemctl enable docker

Dockerfileの作成

完成イメージ

.
├── Dockerfile        # コンテナの起動イメージの内容
├── requirements.txt  # ライブラリ(依存パッケージ)一覧
├── bot.log           # ログ(コンテナ内と共有)
├── config.json       # 設定ファイル
├── functions         # 関数群
│   ├── check.py
│   └── parse.py
└── main.py           # Discord Bot の main スクリプト

ファイル作成

touch Dockerfile
FROM python:3.12-slim

WORKDIR /bot

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["python3", "main.py"]

コンテナ起動

sudo docker build -t イメージ名 .
sudo docker run -d --name コンテナの名前 --restart unless-stopped -v $(pwd)/bot.log:/bot/bot.log イメージ名

参考

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?