文書の過去の版を表示しています。
Docker - 仮想化コンテナ
Docker (ドッカー) は、コンテナと呼ばれるOSレベルの仮想化(英語版)環境を提供するオープンソースソフトウェアである。VMware 製品などの完全仮想化を行うハイパーバイザ型製品と比べて、ディスク使用量は少なく、仮想環境(インスタンス) 作成や起動は速く、性能劣化がほとんどないという利点を持つ。
Docker - Wikiwand より
本家: Docker: Accelerated Container Application Development
ソースコード: GitHub - docker/docker-ce: Docker CE
ドキュメント: Docker ドキュメント日本語化プロジェクト — Docker-docs-ja 24.0 ドキュメント
Docker - 仮想化コンテナ (Windows)
インストール
公式: Install Docker Engine on Fedora | Docker Docs 翻訳
$ sudo dnf -y install dnf-plugins-core
メタデータの期限切れの最終確認: 1:53:37 時間前の 2023年09月06日 13時37分34秒 に実施しました。 パッケージ dnf-plugins-core-4.4.2-1.fc38.noarch は既にインストールされています。 依存関係が解決しました。 行うべきことはありません。 完了しました!
$ sudo dnf config-manager --add-repo https://download.docker.com/linux/fedora/docker-ce.repo
repo の追加: https://download.docker.com/linux/fedora/docker-ce.repo
$ sudo dnf install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
Docker CE Stable - x86_64 23 kB/s | 14 kB 00:00 依存関係が解決しました。 ==================================================================================================================== パッケージ アーキテクチャー バージョン リポジトリー サイズ ==================================================================================================================== インストール: containerd.io x86_64 1.6.22-3.1.fc38 docker-ce-stable 33 M docker-buildx-plugin x86_64 0.11.2-1.fc38 docker-ce-stable 13 M docker-ce x86_64 3:24.0.6-1.fc38 docker-ce-stable 24 M docker-ce-cli x86_64 1:24.0.6-1.fc38 docker-ce-stable 7.1 M docker-compose-plugin x86_64 2.21.0-1.fc38 docker-ce-stable 13 M 依存関係のインストール: docker-ce-rootless-extras x86_64 24.0.6-1.fc38 docker-ce-stable 3.9 M libcgroup x86_64 3.0-2.fc38 fedora 75 k トランザクションの概要 ==================================================================================================================== インストール 7 パッケージ ダウンロードサイズの合計: 93 M インストール後のサイズ: 366 M これでよろしいですか? [y/N]: y パッケージのダウンロード: (1/7): docker-buildx-plugin-0.11.2-1.fc38.x86_64.rpm 1.5 MB/s | 13 MB 00:08 (2/7): docker-ce-24.0.6-1.fc38.x86_64.rpm 1.5 MB/s | 24 MB 00:15 (3/7): docker-ce-cli-24.0.6-1.fc38.x86_64.rpm 917 kB/s | 7.1 MB 00:07 (4/7): docker-ce-rootless-extras-24.0.6-1.fc38.x86_64.rpm 1.5 MB/s | 3.9 MB 00:02 (5/7): libcgroup-3.0-2.fc38.x86_64.rpm 82 kB/s | 75 kB 00:00 (6/7): containerd.io-1.6.22-3.1.fc38.x86_64.rpm 1.4 MB/s | 33 MB 00:23 (7/7): docker-compose-plugin-2.21.0-1.fc38.x86_64.rpm 1.8 MB/s | 13 MB 00:06 -------------------------------------------------------------------------------------------------------------------- 合計 3.6 MB/s | 93 MB 00:25 Docker CE Stable - x86_64 7.8 kB/s | 1.6 kB 00:00 GPG 鍵 0x621E9F35 をインポート中: Userid : "Docker Release (CE rpm) <docker@docker.com>" Fingerprint: 060A 61C5 1B55 8A7F 742B 77AA C52F EB6B 621E 9F35 From : https://download.docker.com/linux/fedora/gpg これでよろしいですか? [y/N]: y 鍵のインポートに成功しました トランザクションの確認を実行中 トランザクションの確認に成功しました。 トランザクションのテストを実行中 トランザクションのテストに成功しました。 トランザクションを実行中 準備 : 1/1 インストール中 : docker-compose-plugin-2.21.0-1.fc38.x86_64 1/7 scriptletの実行中: docker-compose-plugin-2.21.0-1.fc38.x86_64 1/7 インストール中 : libcgroup-3.0-2.fc38.x86_64 2/7 インストール中 : docker-buildx-plugin-0.11.2-1.fc38.x86_64 3/7 scriptletの実行中: docker-buildx-plugin-0.11.2-1.fc38.x86_64 3/7 インストール中 : docker-ce-cli-1:24.0.6-1.fc38.x86_64 4/7 scriptletの実行中: docker-ce-cli-1:24.0.6-1.fc38.x86_64 4/7 インストール中 : containerd.io-1.6.22-3.1.fc38.x86_64 5/7 scriptletの実行中: containerd.io-1.6.22-3.1.fc38.x86_64 5/7 インストール中 : docker-ce-rootless-extras-24.0.6-1.fc38.x86_64 6/7 scriptletの実行中: docker-ce-rootless-extras-24.0.6-1.fc38.x86_64 6/7 インストール中 : docker-ce-3:24.0.6-1.fc38.x86_64 7/7 scriptletの実行中: docker-ce-3:24.0.6-1.fc38.x86_64 7/7 検証 : containerd.io-1.6.22-3.1.fc38.x86_64 1/7 検証 : docker-buildx-plugin-0.11.2-1.fc38.x86_64 2/7 検証 : docker-ce-3:24.0.6-1.fc38.x86_64 3/7 検証 : docker-ce-cli-1:24.0.6-1.fc38.x86_64 4/7 検証 : docker-ce-rootless-extras-24.0.6-1.fc38.x86_64 5/7 検証 : docker-compose-plugin-2.21.0-1.fc38.x86_64 6/7 検証 : libcgroup-3.0-2.fc38.x86_64 7/7 インストール済み: containerd.io-1.6.22-3.1.fc38.x86_64 docker-buildx-plugin-0.11.2-1.fc38.x86_64 docker-ce-3:24.0.6-1.fc38.x86_64 docker-ce-cli-1:24.0.6-1.fc38.x86_64 docker-ce-rootless-extras-24.0.6-1.fc38.x86_64 docker-compose-plugin-2.21.0-1.fc38.x86_64 libcgroup-3.0-2.fc38.x86_64 完了しました!
$ sudo systemctl enable --now docker
Created symlink /etc/systemd/system/multi-user.target.wants/docker.service → /usr/lib/systemd/system/docker.service.
$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally latest: Pulling from library/hello-world 719385e32844: Pull complete Digest: sha256:dcba6daec718f547568c562956fa47e1b03673dd010fe6ee58ca806767031d1c Status: Downloaded newer image for hello-world:latest Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
インストール後の手順
Linux post-installation steps for Docker Engine | Docker Docs 翻訳
Docker デーモンは Unix ソケットにバインドするので、デフォルトでは、Unix ソケットを所有するのは root ユーザーであり、他のユーザーは sudo を使用してのみそれにアクセスできる。Docker デーモンは常に root ユーザーとして実行される。
$ docker run hello-world
docker: permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Post "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/create": dial unix /var/run/docker.sock: connect: permission denied. See 'docker run --help'.
$ sudo ls -al /var/run/docker.sock
srw-rw---- 1 root docker 0 9月 6 15:43 /var/run/docker.sock
非 root ユーザーとして Docker を管理するには… (開発環境向け)
docker グループを作成する。(通常はインストール時に作成されている)
$ sudo groupadd docker
groupadd: グループ 'docker' は既に存在します
Docker を管理するユーザーを docker グループに追加する。
$ id tomoyan
uid=1000(tomoyan) gid=1000(tomoyan) groups=1000(tomoyan),10(wheel),135(mock)
$ sudo usermod -aG docker $USER
$ id tomoyan
uid=1000(tomoyan) gid=1000(tomoyan) groups=1000(tomoyan),10(wheel),135(mock),974(docker)
再ログインするか、もしくは、以下のコマンドを実行してグループへの変更を有効化する。
$ newgrp docker
開発環境では docker グループに所属するユーザーは、sudo で管理者実行する必要がなくなるので作業効率がアップします😍💕💕💕
$ docker run hello-world
Hello from Docker! This message shows that your installation appears to be working correctly. To generate this message, Docker took the following steps: 1. The Docker client contacted the Docker daemon. 2. The Docker daemon pulled the "hello-world" image from the Docker Hub. (amd64) 3. The Docker daemon created a new container from that image which runs the executable that produces the output you are currently reading. 4. The Docker daemon streamed that output to the Docker client, which sent it to your terminal. To try something more ambitious, you can run an Ubuntu container with: $ docker run -it ubuntu bash Share images, automate workflows, and more with a free Docker ID: https://hub.docker.com/ For more examples and ideas, visit: https://docs.docker.com/get-started/
Docker からこんにちは! このメッセージは、インストールが正しく動作していることを示しています。 このメッセージを生成するために、Docker は次の手順を実行しました。 1. Docker クライアントが Docker デーモンに接続しました。 2. Docker デーモンは、Docker Hub から「hello-world」イメージをプルしました。 (amd64) 3. Docker デーモンは、そのイメージから新しいコンテナを作成し、 現在読んでいる出力を生成する実行可能ファイル。 4. Docker デーモンはその出力を Docker クライアントにストリーミングし、Docker クライアントがそれを送信しました。 端末に。 もっと野心的なことを試すには、次のコマンドを使用して Ubuntu コンテナを実行できます。 $ docker run -it ubuntu bash 無料の Docker ID を使用して、イメージを共有したり、ワークフローを自動化したりできます。 https://hub.docker.com/ その他の例やアイデアについては、以下を参照してください。 https://docs.docker.com/get-started/
使い方
コンテナビルド [build]
+ ヘルプ [--help]
$ docker build --help
Usage: docker buildx build [OPTIONS] PATH | URL | - Start a build Aliases: docker buildx build, docker buildx b Options: --add-host strings Add a custom host-to-IP mapping (format: "host:ip") --allow strings Allow extra privileged entitlement (e.g., "network.host", "security.insecure") --annotation stringArray Add annotation to the image --attest stringArray Attestation parameters (format: "type=sbom,generator=image") --build-arg stringArray Set build-time variables --build-context stringArray Additional build contexts (e.g., name=path) --builder string Override the configured builder instance (default "default") --cache-from stringArray External cache sources (e.g., "user/app:cache", "type=local,src=path/to/dir") --cache-to stringArray Cache export destinations (e.g., "user/app:cache", "type=local,dest=path/to/dir") --cgroup-parent string Set the parent cgroup for the "RUN" instructions during build -f, --file string Name of the Dockerfile (default: "PATH/Dockerfile") --iidfile string Write the image ID to the file --label stringArray Set metadata for an image --load Shorthand for "--output=type=docker" --metadata-file string Write build result metadata to the file --network string Set the networking mode for the "RUN" instructions during build (default "default") --no-cache Do not use cache when building the image --no-cache-filter stringArray Do not cache specified stages -o, --output stringArray Output destination (format: "type=local,dest=path") --platform stringArray Set target platform for build --progress string Set type of progress output ("auto", "plain", "tty"). Use plain to show container output (default "auto") --provenance string Shorthand for "--attest=type=provenance" --pull Always attempt to pull all referenced images --push Shorthand for "--output=type=registry" -q, --quiet Suppress the build output and print image ID on success --sbom string Shorthand for "--attest=type=sbom" --secret stringArray Secret to expose to the build (format: "id=mysecret[,src=/local/secret]") --shm-size bytes Size of "/dev/shm" --ssh stringArray SSH agent socket or keys to expose to the build (format: "default|<id>[=<socket>|<key>[,<key>]]") -t, --tag stringArray Name and optionally a tag (format: "name:tag") --target string Set the target build stage to build --ulimit ulimit Ulimit options (default [])
コンテナ実行 [run]
+ ヘルプ [--help]
$ docker run --help
Usage: docker run [OPTIONS] IMAGE [COMMAND] [ARG...] Create and run a new container from an image Aliases: docker container run, docker run Options: --add-host list Add a custom host-to-IP mapping (host:ip) --annotation map Add an annotation to the container (passed through to the OCI runtime) (default map[]) -a, --attach list Attach to STDIN, STDOUT or STDERR --blkio-weight uint16 Block IO (relative weight), between 10 and 1000, or 0 to disable (default 0) --blkio-weight-device list Block IO weight (relative device weight) (default []) --cap-add list Add Linux capabilities --cap-drop list Drop Linux capabilities --cgroup-parent string Optional parent cgroup for the container --cgroupns string Cgroup namespace to use (host|private) 'host': Run the container in the Docker host's cgroup namespace 'private': Run the container in its own private cgroup namespace '': Use the cgroup namespace as configured by the default-cgroupns-mode option on the daemon (default) --cidfile string Write the container ID to the file --cpu-period int Limit CPU CFS (Completely Fair Scheduler) period --cpu-quota int Limit CPU CFS (Completely Fair Scheduler) quota --cpu-rt-period int Limit CPU real-time period in microseconds --cpu-rt-runtime int Limit CPU real-time runtime in microseconds -c, --cpu-shares int CPU shares (relative weight) --cpus decimal Number of CPUs --cpuset-cpus string CPUs in which to allow execution (0-3, 0,1) --cpuset-mems string MEMs in which to allow execution (0-3, 0,1) -d, --detach Run container in background and print container ID --detach-keys string Override the key sequence for detaching a container --device list Add a host device to the container --device-cgroup-rule list Add a rule to the cgroup allowed devices list --device-read-bps list Limit read rate (bytes per second) from a device (default []) --device-read-iops list Limit read rate (IO per second) from a device (default []) --device-write-bps list Limit write rate (bytes per second) to a device (default []) --device-write-iops list Limit write rate (IO per second) to a device (default []) --disable-content-trust Skip image verification (default true) --dns list Set custom DNS servers --dns-option list Set DNS options --dns-search list Set custom DNS search domains --domainname string Container NIS domain name --entrypoint string Overwrite the default ENTRYPOINT of the image -e, --env list Set environment variables --env-file list Read in a file of environment variables --expose list Expose a port or a range of ports --gpus gpu-request GPU devices to add to the container ('all' to pass all GPUs) --group-add list Add additional groups to join --health-cmd string Command to run to check health --health-interval duration Time between running the check (ms|s|m|h) (default 0s) --health-retries int Consecutive failures needed to report unhealthy --health-start-period duration Start period for the container to initialize before starting health-retries countdown (ms|s|m|h) (default 0s) --health-timeout duration Maximum time to allow one check to run (ms|s|m|h) (default 0s) --help Print usage -h, --hostname string Container host name --init Run an init inside the container that forwards signals and reaps processes -i, --interactive Keep STDIN open even if not attached --ip string IPv4 address (e.g., 172.30.100.104) --ip6 string IPv6 address (e.g., 2001:db8::33) --ipc string IPC mode to use --isolation string Container isolation technology --kernel-memory bytes Kernel memory limit -l, --label list Set meta data on a container --label-file list Read in a line delimited file of labels --link list Add link to another container --link-local-ip list Container IPv4/IPv6 link-local addresses --log-driver string Logging driver for the container --log-opt list Log driver options --mac-address string Container MAC address (e.g., 92:d0:c6:0a:29:33) -m, --memory bytes Memory limit --memory-reservation bytes Memory soft limit --memory-swap bytes Swap limit equal to memory plus swap: '-1' to enable unlimited swap --memory-swappiness int Tune container memory swappiness (0 to 100) (default -1) --mount mount Attach a filesystem mount to the container --name string Assign a name to the container --network network Connect a container to a network --network-alias list Add network-scoped alias for the container --no-healthcheck Disable any container-specified HEALTHCHECK --oom-kill-disable Disable OOM Killer --oom-score-adj int Tune host's OOM preferences (-1000 to 1000) --pid string PID namespace to use --pids-limit int Tune container pids limit (set -1 for unlimited) --platform string Set platform if server is multi-platform capable --privileged Give extended privileges to this container -p, --publish list Publish a container's port(s) to the host -P, --publish-all Publish all exposed ports to random ports --pull string Pull image before running ("always", "missing", "never") (default "missing") -q, --quiet Suppress the pull output --read-only Mount the container's root filesystem as read only --restart string Restart policy to apply when a container exits (default "no") --rm Automatically remove the container when it exits --runtime string Runtime to use for this container --security-opt list Security Options --shm-size bytes Size of /dev/shm --sig-proxy Proxy received signals to the process (default true) --stop-signal string Signal to stop the container --stop-timeout int Timeout (in seconds) to stop a container --storage-opt list Storage driver options for the container --sysctl map Sysctl options (default map[]) --tmpfs list Mount a tmpfs directory -t, --tty Allocate a pseudo-TTY --ulimit ulimit Ulimit options (default []) -u, --user string Username or UID (format: <name|uid>[:<group|gid>]) --userns string User namespace to use --uts string UTS namespace to use -v, --volume list Bind mount a volume --volume-driver string Optional volume driver for the container --volumes-from list Mount volumes from the specified container(s) -w, --workdir string Working directory inside the container
$ docker build --help