Dockerまわりのメモ
devcontainerでdocker.ioのイメージを使用すると reopen in container が失敗していた.その際,次のエラーが表示されていた. (mcr.microsoft.comのイメージだと問題なかった.)
The editor cannot be opened due to an unexpected error: No file system provider found for resource 'vscode-remote://...
devcontainer.jsonの remoteUser をコメントアウトすると直った.(rootになるらしい)
devcontainerでcompose.ymlを使おうとすると,reopen in container でエラーが出た.
[213651 ms] Error: Command failed: docker-compose version --short
at vc (/root/.vscode-remote-containers/dist/dev-containers-cli-0.255.4/dist/spec-node/devContainersSpecCLI.js:1859:904)
at processTicksAndRejections (node:internal/process/task_queues:96:5)
at async EO (/root/.vscode-remote-containers/dist/dev-containers-cli-0.255.4/dist/spec-node/devContainersSpecCLI.js:1787:19035)
at async _ae (/root/.vscode-remote-containers/dist/dev-containers-cli-0.255.4/dist/spec-node/devContainersSpecCLI.js:1994:26821)
docker composeを使っていたが,仕方がないので, docker-compose を入れたら直った.
インストール先は,/usr/local/bin のほうが良いのかもしれない.
sudo curl -L https://github.com/docker/compose/releases/download/v2.12.2/docker-compose-`uname -s`-`uname -m` -o /usr/bin/docker-compose
sudo chmod +x /usr/bin/docker-compose
Go言語
buster と bullseye は Debian v10 と v11 の別名
buster と bullseye はそれぞれ Debian のバージョンに付けられた別名.
buster は v10 で, bullseye は v11 を表す.
alpine は実験的で予期しない動作をするかもしれない
alpineは小さいイメージだが,実験的で,glibcなどを置き換えているため,予期しない動作をする場合があるらしい
This image is based on the popular Alpine Linux project, available in the alpine official image. Alpine Linux is much smaller than most distribution base images (~5MB), and thus leads to much slimmer images in general.
This variant is highly experimental, and not officially supported by the Go project (see golang/go#19938 for details).
The main caveat to note is that it does use musl libc instead of glibc and friends, which can lead to unexpected behavior. See this Hacker News comment thread for more discussion of the issues that might arise and some pro/con comparisons of using Alpine-based images.
To minimize image size, additional related tools (such as git, gcc, or bash) are not included in Alpine-based images. Using this image as a base, add the things you need in your own Dockerfile (see the alpine image description for examples of how to install packages if you are unfamiliar). See also docker-library/golang#250 (comment) for a longer explanation.
mcr.microsoft.com/devcontainers/go イメージを定義するDockerfileの場所
見つけるまでの履歴
The dev container definitions displayed come from the vscode-dev-containers repository. You can browse the containers folder of that repository to see the contents of each definition.
↓のフォルダに各コンテナイメージ一覧がある.
ちなみに,vscode-remote-try-go の .devcontainer/Dockerfile にもURLが記載されている.
devcontainer の reopen in container で出たエラー.
devcontainer.json で "remoteUser": "vscode" を設定したが,vscodeユーザーがいないので,Dockerfileで設定した.
RUN adduser vscode
[2022-11-03T13:12:35.952Z] Start: Run in container: cat /etc/passwd
[2022-11-03T13:12:35.952Z] Stdin closed!
[2022-11-03T13:12:35.952Z] Error: An error occurred setting up the container.
devcontainer.json の customizations
Mac
dockerが入っていないことを確認する.
docker
zsh: command not found: docker
ダウンロードしたDocker.dmgを開いて,表示されたウィンドウ内のDocker.appをApplicationにドラッグアンドドロップする.
ウィンドウを閉じる.
Docker.appを開く.
Docker Desktop needs privileged access.の警告が出たのでパスワードを入力する.
同意画面で同意する.
docker version
Client:
Cloud integration: v1.0.29
Version: 20.10.20
API version: 1.41
Go version: go1.18.7
Git commit: 9fdeb9c
Built: Tue Oct 18 18:20:35 2022
OS/Arch: darwin/arm64
Context: default
Experimental: true
Server: Docker Desktop 4.13.1 (90346)
Engine:
Version: 20.10.20
API version: 1.41 (minimum version 1.12)
Go version: go1.18.7
Git commit: 03df974
Built: Tue Oct 18 18:18:16 2022
OS/Arch: linux/arm64
Experimental: false
containerd:
Version: 1.6.8
GitCommit: 9cd3357b7fd7218e4aec3eae239db1f68a5a6ec6
runc:
Version: 1.1.4
GitCommit: v1.1.4-0-g5fd4c4d
docker-init:
Version: 0.19.0
GitCommit: de40ad0
MySQL
最小限の構成
version: '3'
services:
mysqldb:
image: mysql:latest
environment:
MYSQL_ROOT_PASSWORD: root # MySQLパスワード設定
volumes:
- mysql-data:/var/lib/mysql # MySQLのデータをマウントする
volumes:
mysql-data:
サービス用のコンテナを構築、作成、起動して,バックグラウンドで実行.
docker-compose up -d
コマンドを実行して,bashを起動.
docker-compose exec mysqldb bash
コンテナの中で
mysql -u root -p
パスワード入力
root