Docker入門

Dokcerとは?

公式サイト

Empowering App Development for Developers | Docker

Docker offers free plans for individual developers and teams just starting out. We also have new monthly plans for teams of developers with more advanced requirements. Learn more about our free, professional, and team subscriptions.

概要

Docker overview

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications.

Docker is an open platform for developing, shipping, and running applications. Docker enables you to separate your applications from your infrastructure so you can deliver software quickly. With Docker, you can manage your infrastructure in the same ways you manage your applications. By taking advantage of Docker’s methodologies for shipping, testing, and deploying code quickly, you can significantly reduce the delay between writing code and running it in production.

Docker Documentation

Dockerは、アプリケーションを開発、出荷、実行するオープンなプラットフォームである。

Dockerを使うことで、アプリケーションとインフラを分離することができ、ソフトウェアを素早く届けることができる。

Dockerを使えば、アプリケーションを管理するのと同じようにインフラを管理できる。

Dockerの方法論の利点を活かして、素早くコードを出荷し、テストし、デプロイすることで、コードを書いて本番で実行するまでの時間を大いに削減できる。

※shippingの訳が気になる・・・

環境構築 ※CentOS8

$ dnf config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
$ dnf -y install docker-ce docker-ce-cli containerd.io

これで無事Installが完了するでしょう。

で、dockerは起動されてないので、起動します。

$ systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor pre...
Active: inactive (dead)
Docs: https://docs.docker.com

$ systemctl start docker

$ systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/usr/lib/systemd/system/docker.service; disabled; vendor pre...
Active: active (running) since Mon 2020-10-26 23:21:49 JST; 27s ago
Docs: https://docs.docker.com
Main PID: 769013 (dockerd)
Tasks: 8
Memory: 119.6M
CGroup: /system.slice/docker.service
└─769013 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/cont>
Oct 26 23:21:48 xxxx.xxxx.jp dockerd[769013]: time="2020-10-26...
Oct 26 23:21:48 xxxx.xxxx.jp dockerd[769013]: time="2020-10-26...
Oct 26 23:21:48 xxxx.xxxx.jp dockerd[769013]: time="2020-10-26...
Oct 26 23:21:48 xxxx.xxxx.jp dockerd[769013]: time="2020-10-26...
Oct 26 23:21:49 xxxx.xxxx.jp dockerd[769013]: time="2020-10-26...
Oct 26 23:21:49 xxxx.xxxx.jp dockerd[769013]: time="2020-10-26...
Oct 26 23:21:49 xxxx.xxxx.jp dockerd[769013]: time="2020-10-26...
Oct 26 23:21:49 xxxx.xxxx.jp dockerd[769013]: time="2020-10-26...
Oct 26 23:21:49 xxxx.xxxx.jp dockerd[769013]: time="2020-10-26...
Oct 26 23:21:49 xxxx.xxxx.jp systemd[1]: Started Docker Applic...

コマンド

ps

コンテナの状況を確認。

$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d4cc9424f953 linuxserver/xxx "/init" 2 days ago Up 2 days 0.0.0.0:8081->80/udp xxx_1
79ca8d8284f3 linuxserver/xxx "/init" 2 days ago Up 2 days 0.0.0.0:8082->80/udp xxx_2
735b0162fe22 linuxserver/xxx "/init" 2 days ago Up 2 days 0.0.0.0:8083->80/udp xxx_3

exec

コンテナでコマンドを実行。

$ docker exec -it 735b0162fe22 date
Tue Oct 27 00:37:39 JST 2020

logs

コンテナのログ確認。

$ docker logs 735b0162fe22
[s6-init] making user provided files available at /var/run/s6/etc…exited 0.
[s6-init] ensuring user provided files have correct perms…exited 0.
[fix-attrs.d] applying ownership & permissions fixes…
[fix-attrs.d] done.
[cont-init.d] executing container initialization scripts…
[cont-init.d] 01-envfile: executing…
[cont-init.d] 01-envfile: exited 0.
[cont-init.d] 10-adduser: executing…

stats

コンテナのリソース使用状況確認。

$ docker stats
CONTAINER ID NAME CPU % MEM USAGE / LIMIT MEM % NET I/O BLOCK I/O PIDS
d4cc9424f953 xxx_1 0.05% 12.17MiB / 818.6MiB 1.49% 368MB / 384MB 15.8MB / 381kB 12
79ca8d8284f3 xxx_2 0.00% 14.53MiB / 818.6MiB 1.77% 3.1GB / 3.21GB 2.38MB / 381kB 12
735b0162fe22 xxx_3 0.02% 16.66MiB / 818.6MiB 2.03% 486MB / 486MB 59.9MB / 381kB 12