labunix's blog

labunixのラボUnix

debian bookwormでdockerを入れてみる

■debian bookwormでdockerを入れてみる

 Raspberry Pi 4B(Ubuntu 20.04)にdockerを導入する。
 https://labunix.hateblo.jp/entry/20200922/1600763805

$  lsb_release -d;uname -r -m
No LSB modules are available.
Description:	Debian GNU/Linux 12 (bookworm)
6.1.0-13-amd64 x86_64

■「docker-compose」をインストールする

$ apt-cache search ^docker
debocker - docker-powered package builder for Debian
docker - transitional package
docker-clean - simple Shell script to clean up the Docker Daemon
docker-compose - define and run multi-container Docker applications with YAML
docker-registry - Docker toolset to pack, ship, store, and deliver content
golang-github-docker-distribution-dev - Docker toolset to pack, ship, store, and deliver content (source)
docker-doc - Linux container runtime -- documentation
docker.io - Linux container runtime
golang-github-fsouza-go-dockerclient-dev - Docker client library in Go
golang-github-samalba-dockerclient-dev - Docker client library in Go

$ sudo apt-get install -y docker-compose

$ docker -v
Docker version 20.10.24+dfsg1, build 297e128

$ sudo docker version
Client:
 Version:           20.10.24+dfsg1
 API version:       1.41
 Go version:        go1.19.8
 Git commit:        297e128
 Built:             Thu May 18 08:38:34 2023
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server:
 Engine:
  Version:          20.10.24+dfsg1
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.19.8
  Git commit:       5d6db84
  Built:            Thu May 18 08:38:34 2023
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.6.20~ds1
  GitCommit:        1.6.20~ds1-1+b1
 runc:
  Version:          1.1.5+ds1
  GitCommit:        1.1.5+ds1-1+b1
 docker-init:
  Version:          0.19.0
  GitCommit:        

■dockerグループに追加

$ sudo gpasswd docker -a labunix
$ exit

■基本コマンドの確認

$ echo "image container volume network" | \
  awk '{for(a=1;a<=NF;a++){print "echo \042\134$docker "$a" ls\042;docker",$a,"ls"}}' | sh
$docker image ls
REPOSITORY   TAG       IMAGE ID   CREATED   SIZE
$docker container ls
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
$docker volume ls
DRIVER    VOLUME NAME
$docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
d6eaa885c6b2   bridge    bridge    local
1d05c6c327be   host      host      local
8a472b9ea5b6   none      null      local

■dockerイメージの検索
 オフィシャルじゃないのはだいたいgitからなので。。。

$ sudo apt-get install -y curl

$ docker search -f is-official=true lisp
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
clojure   Clojure is a dialect of Lisp that runs on th…   354       [OK]       
hylang    Hy is a Lisp dialect that translates express…   58        [OK]       

$ docker search -f is-official=true redmine
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
redmine   Redmine is a flexible project management web…   1169      [OK]  

$ docker search -f is-official=true nginx
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
nginx     Official build of Nginx.                        19188     [OK]       
unit      Official build of NGINX Unit: Universal Web …   16        [OK]      

■とりあえず、Hello Worldを。。。

$ docker container run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
719385e32844: Pull complete 
Digest: sha256:88ec0acaa3ec199d3b7eaf73588f4518c25f9d34f58ce9a0df68429c5af48e8d
Status: Downloaded newer image for hello-world:latest
...


$ docker container ls -a
CONTAINER ID   IMAGE         COMMAND    CREATED          STATUS                      PORTS     NAMES
7970c8124c5c   hello-world   "/hello"   51 seconds ago   Exited (0) 50 seconds ago             peaceful_curran

$ docker logs 7970c8124c5c

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 volume ls
DRIVER    VOLUME NAME

$ docker images -a
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    9c7a54a9a43c   6 months ago   13.3kB

$ docker ps -a
CONTAINER ID   IMAGE         COMMAND    CREATED         STATUS                     PORTS     NAMES
7970c8124c5c   hello-world   "/hello"   6 minutes ago   Exited (0) 6 minutes ago             peaceful_curran

$ docker rm 7970c8124c5c
7970c8124c5c

$ docker rmi 9c7a54a9a43c
Untagged: hello-world:latest
Untagged: hello-world@sha256:88ec0acaa3ec199d3b7eaf73588f4518c25f9d34f58ce9a0df68429c5af48e8d
Deleted: sha256:9c7a54a9a43cca047013b82af109fe963fde787f63f9e016fdc3384500c2823d
Deleted: sha256:01bb4fce3eb1b56b05adf99504dafd31907a5aadac736e36b27595c8b92f07f1