作りたいもの

a graph image

Docker Compose

https://github.com/kagyuu/docker_ai_study/blob/main/docker-compose.yml

version: "3.9"
services:
  keras:
    build:
      context: .
      dockerfile: Dockerfile-gpu
    secrets:
      - user_ssh_pub
      - user_git_key
      - user_git_config
    ports:
      - '2222:22'
    volumes:
      # $ sudo chown -R 5000:5000 /var/keras-data
      - /var/keras-data:/home/aichan
    deploy:
      resources:
        reservations:
          devices:
            - driver: nvidia
              count: 1
              # device_ids: ['0', '3']
              capabilities: [ gpu ]
    restart: always

  postgres:
    image: postgres:latest
    container_name: postgres
    user: 5050:5050
    volumes:
      # $ sudo chown -R 5050:5050 <host_directory>
      - /var/pgsql-data/initdb.d/:/docker-entrypoint-initdb.d/
      - /var/pgsql-data/data:/var/lib/postgresql/data
    environment:
      POSTGRES_USER: root
      POSTGRES_PASSWORD: root
      POSTGRES_INITDB_ARGS: "--encoding=UTF-8"
    hostname: postgres
    restart: always

  pgadmin4:
    image: dpage/pgadmin4:latest
    container_name: pgadmin4
    volumes:
      # $ sudo chown -R 5050:5050 <host_directory>
      - /var/pgadmin-data:/var/lib/pgadmin
    environment:
      PGADMIN_DEFAULT_EMAIL: root@example.com
      PGADMIN_DEFAULT_PASSWORD: root
      PGADMIN_DISABLE_POSTFIX: "False"
    hostname: pgadmin4
    depends_on:
      - postgres
    restart: always

secrets:
  user_ssh_pub:
    file: /home/atsushi/.ssh/id_rsa.pub
  user_git_key:
    file: /home/atsushi/.ssh/id_rsa.github
  user_git_config:
    file: /home/atsushi/.ssh/config

 

https://github.com/kagyuu/docker_ai_study/blob/main/Dockerfile-gpu

FROM nvidia/cuda:11.4.1-devel-ubuntu20.04

# To avoid the command prompt for the timezon setting
ENV DEBIAN_FRONTEND=noninteractive
ENV TZ=ETC/UTC 

# Add 3rd party's apt repositiories.
RUN apt-get update \
&& yes | unminimize \
&& apt-get -y upgrade \
&& apt-get -y install apt-utils curl wget lsb-release \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN curl -fsSL https://deb.nodesource.com/setup_16.x | bash -

RUN echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list
RUN wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add -

# Unminimize Ubuntu image.
RUN apt-get update \
&& apt-get -y install vim iputils-ping iproute2 git sudo htop \
openssh-server \
python3 python3-venv python3-pip python3-dev swig \
default-jdk maven ant gradle \
nodejs postgresql-client \
libreadline-gplv2-dev libncursesw5-dev libsqlite3-dev tk-dev libgdbm-dev libgdbm-compat-dev \
libbz2-dev libssl-dev libsqlite3-dev libffi-dev liblzma-dev libpq-dev \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*

RUN npm install -g npm && npm install -g yarn sort-package-json npm-check-updates typescript ts-node tslab

#####
# Install Openssh
RUN mkdir -p /var/run/sshd && sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin yes/' /etc/ssh/sshd_config

# SSH login fix. Otherwise user is kicked off after login
RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd

#####
# Install Poetry
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python3 - 
RUN echo "export PATH=$PATH:/root/.local/bin" >> /root/.bashrc
RUN mkdir -p /etc/bash_completion.d/ && /root/.local/bin/poetry completions bash > /etc/bash_completion.d/poetry.bash-completion

#####
# Build Python 3.10 from its source.
RUN cd /root \
&& yes | git clone https://github.com/python/cpython.git -b 3.10 \
&& cd cpython \
&& ./configure --enable-optimizations | tee configure.log \
&& make -j$(nproc) | tee build.log \
&& make altinstall

ARG USER=aichan
ARG PASSWD=passwd
RUN groupadd -g 5000 ${USER} && useradd -m -s /bin/bash ${USER} -u 5000 -g 5000 && gpasswd -a ${USER} sudo
RUN echo "${USER}:${PASSWD}" | sudo chpasswd

EXPOSE 22
CMD mkdir -p /home/aichan/.ssh && \
    cat /run/secrets/user_ssh_pub >> /home/aichan/.ssh/authorized_keys && \
    chmod 0600 /home/aichan/.ssh/authorized_keys &&  \
    cp /run/secrets/user_git_config /home/aichan/.ssh/config &&  \
    cp /run/secrets/user_git_key /home/aichan/.ssh/id_rsa.github &&  \
    chown -R aichan:aichan /home/aichan/.ssh && \
    /usr/sbin/sshd -D

ビルド

デバック用に、bash でログインする

$ docker-compose ps --service 
keras
postgres
pgadmin

$ docker-compose exec keras /bin/bash

実行

開発環境のVSCode設定

pgadmin4 から postgresql を使う

ssh から postgresql を使う


Docker


添付ファイル: filepgadmin-0.png 115件 [詳細] filepgadmin-1.png 98件 [詳細] filepgadmin-2.png 100件 [詳細] filepgadmin-3.png 105件 [詳細] filepgadmin-4.png 108件 [詳細] filepgadmin-5.png 109件 [詳細] filepgadmin-6.png 98件 [詳細] filepgadmin-7.png 105件 [詳細] filepgadmin-8.png 112件 [詳細] filevscode_keras1.png 137件 [詳細] filevscode_keras2.png 129件 [詳細]

トップ   編集 凍結 差分 バックアップ 添付 複製 名前変更 リロード   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS   sitemap
Last-modified: 2022-02-16 (水) 02:31:14 (131d)
Short-URL: https://at-sushi.com:443/pukiwiki/index.php?cmd=s&k=d1c740caca
ISBN10
ISBN13
9784061426061