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?

DevContainer立ち上げた時のdocker containerの動きを追った件

Posted at

※追った件とか書いていますが、そんな壮大な話ではありません。小さな気づきをメモ程度に書いたものになります。

きっかけ

最近業務でdocker×VSCode DevContainer環境での開発がスタートしたのですが、いまいちDevContainerの動きが分かりにくいな...と気持ち悪さを感じていたので、サクッと検証してみようと思ったことがきっかけでした。

やってみた

手順
VSCode上でWSLからDevContainerを起動し、その後同じWSLを別途立ち上げ、docker ps -aでコンテナがどうなっているかを確認。
※下記docker-compose.yml.devcontainer.jsonを用いて検証

docker-compose.yml
version: '3'
services:
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
    volumes:
      - .:/projroot
      - node_modules:/projroot/frontend/src/node_modules
    ports:
      - "3000:3000"
    tty: true
    environment:
      - WATCHPACK_POLLING=true
    network_mode: "host"

  az-functions:
    build:
      context: ./functions
      dockerfile: Dockerfile
    network_mode: "host"
    volumes:
      - ./:/projroot
    tty: true
    working_dir: /projroot/functions
    environment:
      - DOTNET_SYSTEM_GLOBALIZATION_INVARIANT=1
    ports:
      - '7014:7014'

  db:
    build:
      context: ./db
      dockerfile: Dockerfile
    container_name: postgres-data
    restart: always
    ports:
      - "5555:5432"
    volumes:
      - postgres-data:/var/lib/postgresql/data
    environment:
      - POSTGRES_USER=postgres
      - POSTGRES_PASSWORD=postgres
      - POSTGRES_DB=postgres
      - PGDATA=/var/lib/postgresql/data/pgdata

volumes:
  postgres-data:
  node_modules:
.devcontainer.json
{
    "service": "frontend",
    "name": "device-manager-front",
    "dockerComposeFile": [
        "../docker-compose.yml"
    ],
    "shutdownAction": "none",
    "workspaceFolder": "/projroot/frontend/devicemanager",
    "remoteEnv": {
        "LOCAL_WORKSPACE_FOLDER": "${localWorkspaceFolder}"
    }
}

DevContainer起動後

docker ps -aで一覧表示。docker-compose.ymlで定義されたコンテナが全て動いていました。

CONTAINER ID   IMAGE                                   COMMAND              CREATED        STATUS                        PORTS                                         NAMES
1d85ac29f222   hoge-db             "docker-entrypoint.s…"   10 hours ago   Up 7 seconds                  0.0.0.0:5555->5432/tcp, [::]:5555->5432/tcp   postgres-data
4b25b15c443b   hoge-frontend       "docker-entrypoint.s…"   10 hours ago   Up 7 seconds                                                                hoge-frontend-1
2df969fe69ab   hoge-az-functions   "bash"                   10 hours ago   Up 7 seconds                                                                hoge-az-functions-1
815c3655a083   projroot-az-functions"bash"                  10 hours ago   Up 7 seconds                                              

どうやらDevContainerが起動すると、docker-compose.ymlに記載された内容のコンテナがdocker compose upと同様の挙動で作成される模様です。

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?