Docker入門:インストールから基本的な操作方法
はじめに
CHAPTER 1 Dockerを使う
SECTION 01 Dockerとコンテナ技術について
SECTION 02 Dockerをインストール
$ sudo yum -y update $ sudo yum install -y yum-utils device-mapper-persistent-data lvm2 $ sudo yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo $ sudo yum install -y docker-ce docker-ce-cli containerd.io $ sudo systemctl start docker $ sudo systemctl enable docker $ sudo docker version
CentOS7
- CentOS公式
- 言語:英語
- ネットワーク:有効化
Docker
$ yum install -y yum-utils device-mapper-persistent-data lvm2 $ yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo $ yum install docker-ce docker-ce-cli containerd.io $ systemctl start docker $ systemctl enable docker $ docker version
Windows10 Home
- VirtualBox
- OS:RedHat(64bit)
- CPU:2
- Mem:2GB
- Disk:50GB
- Net:ブリッジ接続
■ Point
- DockerToolboxをインストールすると、Windows10 HomeでもDockerDesktopが利用できる。
SECTION 03 Dockerを体験
$ sudo docker container run hello-world
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.
Nginx
$ sudo docker container run -p 8080:80 nginx
$ sudo docker container run --name mynginx -d -p 8081:80 nginx:1.9.15-alpine
コンテナの確認
$ sudo docker container ls CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES cd6d8608f811 nginx:1.9.15-alpine "nginx -g 'daemon of…" 6 seconds ago Up 4 seconds 443/tcp, 0.0.0.0:8081->80/tcp mynginx 37b5b9d98212 nginx "/docker-entrypoint.…" 11 minutes ago Up 11 minutes 0.0.0.0:8080->80/tcp infallible_easley
コンテナの停止
- NAMES または CONTAINER IDを指定
$ sudo docker container stop mynginx $ sudo docker container stop 37b5b9d98212
イメージの確認
$ sudo docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE nginx latest 992e3b7be046 4 days ago 133MB hello-world latest bf756fb1ae65 9 months ago 13.3kB nginx 1.9.15-alpine 3839248a6963 4 years ago 60.6MB
DockerHubの利用
- アカウント登録が必要
$ sudo docker login Username: Password: $ sudo docker logout
SECTION 04 コンテナの利用法
コンテナのログ確認
$ sudo docker container logs -f 37b5b9d98212
コンテナの確認(停止中のコンテナも含む)
$ sudo docker container ls -a
コンテナの起動(停止中)
$ sudo docker container start 37b5b9d98212
起動していないコンテナを一括破棄
$ sudo docker container prune -f
SECTION 05 Dockerの使いどころ
- 環境依存を無くす
- インフラのコード化
- アプリのマイクロサービス化
おわりに
- Dockerのインストールから基本的な操作方法までをまとめました。
112日目:データベース
データベースの講義11日目です。
【講義内容】
【ワンポイント】
- 最新の日付:MAX() ‐ 貸出中:IS NULL
- 貸出履歴:NOT EXISTS
- 貸出中判定+貸出実績:UNION ALL
【今日の積み上げ】
‐ データベースの基礎
111日目:データベース
データベースの講義10日目です。
【講義内容】
- 第9章 バックアップとリカバリ-障害に備える仕組み-
【ワンポイント】
プロシジャ
DELIMITER | CREATE PROCEDURE insfor(v_max INT) BEGIN DECLARE vid INT DEFAULT 0; REPEAT SET vid = vid + 1; INSERT INTO t1 VALUES(); IF (mod(vid, 10000) = 0) THEN COMMIT; END IF; UNTIL vid >= v_max END REPEAT; END | DELIMITER ; SET autocommit = 0; CALL insfor(20000); DROP PROCEDURE insfor;
データ削除
- 高速、ロールバック不可
- テーブルを削除して、同じ定義でテーブル再作成
TRUNCATE TABLE t1
動作確認
CREATE TABLE t1 ( id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT )ENGINE=Innodb, DEFAULT CHARSET=utf8; INSERT INTO t1 VALUES(); SELECT * FROM t1; START TRANSACTION; TRUNCATE TABLE t1; SELECT * FROM t1; ROLLBACK; SELECT * FROM t1;
- 低速、ロールバック可
- データを1行ずつ削除
DELETE TABLE t1
動作確認
DROP TABLE IF EXISTS t1; CREATE TABLE t1 ( id INT UNSIGNED PRIMARY KEY AUTO_INCREMENT )ENGINE=Innodb, DEFAULT CHARSET=utf8; INSERT INTO t1 VALUES(); SELECT * FROM t1; START TRANSACTION; DELETE FROM t1; SELECT * FROM t1; ROLLBACK; SELECT * FROM t1;
測定結果(データ件数:20万件)
mysql> CALL insfor(200000); Query OK, 0 rows affected (33.01 sec) mysql> TRUNCATE TABLE t1; Query OK, 0 rows affected (0.10 sec) mysql> CALL insfor(200000); Query OK, 0 rows affected (31.80 sec) mysql> DELETE FROM t1; Query OK, 200000 rows affected (5.64 sec)
【今日の積み上げ】
‐ データベースの基礎