Docker-composeをJetson nanoに入れてdockerの起動を楽にする試み。
まずはDocker-composeをインストールする。
sudo apt install python3-pip
sudo apt install build-essential libssl-dev libffi-dev python3-dev
sudo pip3 install docker-compose
-----------
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/tmp/pip-build-pzvne0ph/cryptography/setup.py", line 14, in <module>
from setuptools_rust import RustExtension
ModuleNotFoundError: No module named 'setuptools_rust'
=============================DEBUG ASSISTANCE==========================
If you are seeing an error here please try the following to
successfully install cryptography:
Upgrade to the latest pip and try again. This will fix errors for most
users. See: https://pip.pypa.io/en/stable/installing/#upgrading-pip
=============================DEBUG ASSISTANCE==========================
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-pzvne0ph/cryptography/
そうするとsetuptools_rustが入ってないよ的なエラーが出たので、
sudo pip3 install setuptools_rust
sudo pip3 install docker-compose
とりあえずテストをしてみる。
まず、dockerがちゃんと動くか
docker run --rm hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
93288797bd35: Pull complete
Digest: sha256:cc15c5b292d8525effc0f89cb299f1804f3a725c8d05e158653a563f15e4f685
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.
(arm64v8)
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/
OK
次にdocker-composeで起動してみる。
まず、適当なディレクトリを作り、中にdocker-compose.ymlというファイルを作る。
$ mkdir docker_test
$ cd docker_test
$ nano docker-compose.yml
$ cat docker-compose.yml
version: "2"
services:
app:
image: hello-world
で、
$ docker-compose up
Creating network "docker_test_default" with the default driver
Creating docker_test_app_1 ... done
Attaching to docker_test_app_1
app_1 |
app_1 | Hello from Docker!
app_1 | This message shows that your installation appears to be working correctly.
app_1 |
app_1 | To generate this message, Docker took the following steps:
app_1 | 1. The Docker client contacted the Docker daemon.
app_1 | 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
app_1 | (arm64v8)
app_1 | 3. The Docker daemon created a new container from that image which runs the
app_1 | executable that produces the output you are currently reading.
app_1 | 4. The Docker daemon streamed that output to the Docker client, which sent it
app_1 | to your terminal.
app_1 |
app_1 | To try something more ambitious, you can run an Ubuntu container with:
app_1 | $ docker run -it ubuntu bash
app_1 |
app_1 | Share images, automate workflows, and more with a free Docker ID:
app_1 | https://hub.docker.com/
app_1 |
app_1 | For more examples and ideas, visit:
app_1 | https://docs.docker.com/get-started/
app_1 |
docker_test_app_1 exited with code 0
$ docker-compose images
Container Repository Tag Image Id Size
------------------------------------------------------------------
docker_test_app_1 hello-world latest 18e5af790473 9.136 kB
$ docker-compose ps
Name Command State Ports
--------------------------------------------
docker_test_app_1 /hello Exit 0
$ docker container ls -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
5c4c5e2b5718 hello-world "/hello" About a minute ago Exited (0) 53 seconds ago docker_test_app_1
docker-composeのオプションとしては
$ docker-compose -h
Define and run multi-container applications with Docker.
Usage:
docker-compose [-f <arg>...] [--profile <name>...] [options] [--] [COMMAND] [ARGS...]
docker-compose -h|--help
Options:
-f, --file FILE Specify an alternate compose file
(default: docker-compose.yml)
-p, --project-name NAME Specify an alternate project name
(default: directory name)
--profile NAME Specify a profile to enable
-c, --context NAME Specify a context name
--verbose Show more output
--log-level LEVEL Set log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
--ansi (never|always|auto) Control when to print ANSI control characters
--no-ansi Do not print ANSI control characters (DEPRECATED)
-v, --version Print version and exit
-H, --host HOST Daemon socket to connect to
--tls Use TLS; implied by --tlsverify
--tlscacert CA_PATH Trust certs signed only by this CA
--tlscert CLIENT_CERT_PATH Path to TLS certificate file
--tlskey TLS_KEY_PATH Path to TLS key file
--tlsverify Use TLS and verify the remote
--skip-hostname-check Don't check the daemon's hostname against the
name specified in the client certificate
--project-directory PATH Specify an alternate working directory
(default: the path of the Compose file)
--compatibility If set, Compose will attempt to convert keys
in v3 files to their non-Swarm equivalent (DEPRECATED)
--env-file PATH Specify an alternate environment file
Commands:
build Build or rebuild services
config Validate and view the Compose file
create Create services
down Stop and remove resources
events Receive real time events from containers
exec Execute a command in a running container
help Get help on a command
images List images
kill Kill containers
logs View output from containers
pause Pause services
port Print the public port for a port binding
ps List containers
pull Pull service images
push Push service images
restart Restart services
rm Remove stopped containers
run Run a one-off command
scale Set number of containers for a service
start Start services
stop Stop services
top Display the running processes
unpause Unpause services
up Create and start containers
version Show version information and quit
となっている。
docker-compose up
を実行するとカレントディレクトリのDockerfile、docker-compose.ymlに従ってコンテナを作り、サービスを開始する。
逆に
docker-compose down
を実行するとサービスを停止し、コンテナを破棄する。
$ docker-compose down
Removing test_app_1 ... done
Removing network test_default
docker-compose stop
だとサービスの停止だけでコンテナは残るので
docker-compose start
でサービスをスタートする。
またdownでコンテナを破棄してもイメージは残っている。
$ docker image ls
REPOSITORY TAG IMAGE ID CREATED SIZE
hello-world latest 18e5af790473 2 months ago 9.14kB
必要がなければ
docker image rm 18e
のようにイメージも削除
次はDockerfileとdocker-compose.ymlの中身について解きほぐす。