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 概要まとめ

Last updated at Posted at 2023-10-23

Docker概要

Dockerとは
・Docker社が開発している、Linux をターゲットとするコンテナ管理基盤です。
・Windows版は「Docker Desktop」をダウンロード、インストールし、起動して使う。
(※起動しないと使えない)
Imageとは
・システムの最小構成になっているOS込みのファイル群
Containerとは(
・イメージを指定(マウント)して、OS(サービス)を起動、終了など操作を行える入れ物。
Docker Composeとは
・Dockerのイメージ作成からコンテナ立ち上げまで一連の動作を自動化してくれる指示書のこと。
・Docker Composeは複数のコンテナ(サービス)、ポートなどを一度に行い、各サービスが相互に通信できる状態にしてくれる
→例えば、Nginx、Mysql、Flaskなどのサービスを起動し、相互通信できるようにする(以下参照)

version: '3.8'
services:
  appseed-app:
    container_name: appseed_app
    restart: always
    env_file: .env
    build: .
    networks:
      - db_network
      - web_network
  nginx:
    container_name: nginx
    restart: always
    image: "nginx:latest"
    ports:
      - "5085:5085"
    volumes:
      - ./nginx:/etc/nginx/conf.d
    networks:
      - web_network
    depends_on: 
      - appseed-app
networks:
  db_network:
    driver: bridge
  web_network:
    driver: bridge

Docker hubとは

Docker imageをダウンロード、アップロードすることができる
※Freeライセンスは制限がある

Dockerコンテナの注意点

Dockerコンテナを削除した時点で、ファイルすべて消えてしまいます。

Dockerコマンド

# 名前を付けて実行する(--name:名前)
docker run --name "recommend_app" -it krs_y_test:ver1

# HostからDockerコンテナへコピーする
# from host to container
docker cp test_file.txt container_name:/app/data

# from container to host
docker cp container_name:/app/data/test_file.txt .

詳細はこちら

dockerイメージ作成

# イメージ作成
docker build -t my-app:latest .
# イメージ一覧表示
docker images

docker イメージをExportする

docker save sample-image > sample-image.tar

docker イメージをLoadする

docker load < image.tar
# 実行終わったら自動的にDownするのは後で調べる

Dockerイメージからdockerコンテナを立ちあげる
(runコマンドはイメージからコンテナを作成する一度のみ実行する)

docker run --name <container_name> <image_name>:<image_ver>

docker containerを起動する

# container_appというコンテナを実行する
$ docker start container_app

# コンテナ一覧の確認(停止している場合)
$ docker ps -a
# コンテナを削除する
$ docker rm <container_id>
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?