Open7

ubuntu 20.04 開発環境構築

uniuni

docker install

sudo apt-get remove docker docker-engine docker.io containerd runc
sudo apt-get install     ca-certificates     curl     gnupg     lsb-release
echo   "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io
docker --version
Docker version 20.10.12, build e91ed57

docker ps 
Got permission denied while trying to connect to the Docker daemon socket at unix:///var/run/docker.sock: Get "http://%2Fvar%2Frun%2Fdocker.sock/v1.24/containers/json": dial unix /var/run/docker.sock: connect: permission denied

このままだとsudoつけないと動かせないのでdockerユーザグループに追加

sudo usermod -g docker $USER
sudo /bin/systemctl restart docker.service
id $USER
... gid=998(docker) groups=998(docker),

再起動

sudo reboot

ref.
https://docs.docker.com/engine/install/ubuntu/

uniuni
docker ps
CONTAINER ID   IMAGE     COMMAND   CREATED   STATUS    PORTS     NAMES
uniuni

docker composeの設定

docker compose ps
docker: 'compose' is not a docker command.
See 'docker --help'

docker composeコマンド(Docker Compose v2と名付けられているらしい)はlinuxはデフォルトで入らない

mkdir  ~/.docker/cli-plugins && cd $_
curl -L https://github.com/docker/compose/releases/download/v2.2.3/docker-compose-linux-x86_64 -o docker-compose
chmod +x docker-compose

docker compose --help

Usage:  docker compose [OPTIONS] COMMAND
...

ref.
https://github.com/docker/compose/issues/8630
https://github.com/docker/compose#linux

uniuni

pyenv

  • install pre requirements
sudo apt-get update; sudo apt-get install make build-essential libssl-dev zlib1g-dev \
libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm \
libncursesw5-dev xz-utils tk-dev libxml2-dev libxmlsec1-dev libffi-dev liblzma-dev
  • install and setup
git clone https://github.com/pyenv/pyenv.git ~/.pyenv

# the sed invocation inserts the lines at the start of the file
# after any initial comment lines
sed -Ei -e '/^([^#]|$)/ {a \
export PYENV_ROOT="$HOME/.pyenv"
a \
export PATH="$PYENV_ROOT/bin:$PATH"
a \
' -e ':a' -e '$!{n;ba};}' ~/.profile
echo 'eval "$(pyenv init --path)"' >>~/.profile
echo 'eval "$(pyenv init -)"' >> ~/.bashrc

source ~/.bashrc
  • setup python for global
pyenv install --list
...

pyenv install 3.x.x
pyenv global 3.x.x

python --version
Python 3.x.x

ref.
https://github.com/pyenv/pyenv/wiki#suggested-build-environment
https://github.com/pyenv/pyenv#basic-github-checkout

uniuni

gh

snap経由で入れてと出るが、入れたらgh repo cloneが動かなかった

gh

Command 'gh' not found, but can be installed with:

sudo snap install gh       # version 1.12.1-pre.0-15-gbf5b34d0, or
sudo apt  install gitsome  # version 0.8.0+ds-4

See 'snap info gh' for additional versions.

色々問題が発生するとのことなので、公式の通りにaptで入れた

curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null
sudo apt update
sudo apt install gh

ref.
https://github.com/cli/cli/blob/trunk/docs/install_linux.md#snap-do-not-use
https://github.com/cli/cli/blob/trunk/docs/install_linux.md#debian-ubuntu-linux-raspberry-pi-os-apt

uniuni

docker compose v2でgpu

  • nvidia-dockerをインストール

https://docs.nvidia.com/datacenter/cloud-native/container-toolkit/install-guide.html#docker

に沿ってinstall&docker再起動

cudaのバージョン間違えた。localのものと合わせる必要があるnvidia-smiで確認

ttaching to test-1
Error response from daemon: failed to create shim: OCI runtime create failed: container_linux.go:380: starting container process caused: process_linux.go:545: container init caused: Running hook #0:: error running hook: exit status 1, stdout: , stderr: nvidia-container-cli: requirement error: unsatisfied condition: cuda>=11.6, please update your driver to a newer version, or use an earlier cuda container: unknown

動いた

services:
  test:
    image: nvidia/cuda:11.4.0-runtime-ubuntu20.04
    command: nvidia-smi
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              capabilities: [gpu]
docker compose up
[+] Running 1/0
 ⠿ Container test-1  Recreated 0.0s
Attaching to test-1
test-1  | Thu Mar 24 14:20:59 2022       
test-1  | +-----------------------------------------------------------------------------+
test-1  | | NVIDIA-SMI 470.103.01   Driver Version: 470.103.01   CUDA Version: 11.4     |
test-1  | |-------------------------------+----------------------+----------------------+
test-1  | | GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
test-1  | | Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
test-1  | |                               |                      |               MIG M. |
test-1  | |===============================+======================+======================|
test-1  | |   0  NVIDIA GeForce ...  Off  | 00000000:01:00.0 Off |                  N/A |
test-1  | | N/A   44C    P8     9W /  N/A |     10MiB /  5946MiB |      0%      Default |
test-1  | |                               |                      |                  N/A |
test-1  | +-------------------------------+----------------------+----------------------+
test-1  |                                                                                
test-1  | +-----------------------------------------------------------------------------+
test-1  | | Processes:                                                                  |
test-1  | |  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
test-1  | |        ID   ID                                                   Usage      |
test-1  | |=============================================================================|
test-1  | +-----------------------------------------------------------------------------+
test-1 exited with code 0