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
FROM nvidia/cuda:11.7.0-devel-ubuntu22.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 \
openjdk-17-jdk maven ant gradle \
nodejs postgresql-client \
# -- these libs are needed for building cpython ---
#python3-dev swig \
#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
/var$ ls -la | grep "data" drwxr-xr-x 2 root root 4096 1月 11 11:07 keras-data drwxr-xr-x 14 200 root 4096 1月 13 17:58 nexus-data drwx------ 4 5050 5050 4096 1月 12 01:03 pgadmin-data drwxr-xr-x 4 5050 5050 4096 1月 11 13:14 pgsql-data
$ docker-compose build
$ docker-compose build --no-cache
$ docker-compose ps --service keras postgres pgadmin $ docker-compose exec keras /bin/bash
/Documents/docker_ai_study$ docker-compose up Starting postgres ... done Recreating docker_ai_study_keras_1 ... done Starting pgadmin4 ... done Attaching to postgres, pgadmin4, docker_ai_study_keras_1
/Documents/docker_ai_study$ docker-compose down
/.ssh/config に port forward 設定をする
IdentityFile? は、ホストと同じものを使う。
HOST gpu1
User atsushi
HostName 192.168.10.32
IdentityFile ~/.ssh/id_rsa.gpu1
HOST keras
User root
HostName 192.168.10.32
Port 2222
IdentityFile ~/.ssh/id_rsa.gpu1
LocalForward 20080 pgadmin4:80
LocalForward 28888 localhost:8888
$ ssh keras
Welcome to Ubuntu 20.04.3 LTS (GNU/Linux 5.13.0-27-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
This system has been minimized by removing packages and content that are
not required on a system that users do not log into.
To restore this content, you can run the 'unminimize' command.
Last login: Tue Jan 25 01:55:49 2022 from 192.168.10.4
root@0430468381ec:~# nvidia-smi
Tue Jan 25 01:58:10 2022
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 495.46 Driver Version: 495.46 CUDA Version: 11.5 |
|-------------------------------+----------------------+----------------------+
| GPU Name Persistence-M| Bus-Id Disp.A | Volatile Uncorr. ECC |
| Fan Temp Perf Pwr:Usage/Cap| Memory-Usage | GPU-Util Compute M. |
| | | MIG M. |
|===============================+======================+======================|
| 0 NVIDIA GeForce ... Off | 00000000:01:00.0 Off | N/A |
| 60% 69C P2 172W / 175W | 3443MiB / 7982MiB | 100% Default |
| | | N/A |
+-------------------------------+----------------------+----------------------+
+-----------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=============================================================================|
+-----------------------------------------------------------------------------+
root@0430468381ec:~#
好吃。この状態で http://localhost:20080 で pgadmin4 にアクセスも出来る# psql -h postgres -U root
Password for user root:
root=# \l
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+-------+----------+------------+------------+-------------------
postgres | root | UTF8 | en_US.utf8 | en_US.utf8 |
root | root | UTF8 | en_US.utf8 | en_US.utf8 |
template0 | root | UTF8 | en_US.utf8 | en_US.utf8 | =c/root +
| | | | | root=CTc/root
template1 | root | UTF8 | en_US.utf8 | en_US.utf8 | =c/root +
| | | | | root=CTc/root
testdb | root | UTF8 | en_US.utf8 | en_US.utf8 |
(5 rows)
root=# \c testdb
You are now connected to database "testdb" as user "root".
testdb=# \d
List of relations
Schema | Name | Type | Owner
--------+------------------+----------+-------
public | iris | table | root
public | iris_id_seq | sequence | root
public | iris_name | table | root
public | iris_name_id_seq | sequence | root
(4 rows)
testdb=# select * from iris_name;
id | cd | name
----+----+------------
1 | 0 | setosa
2 | 1 | versicolor
3 | 2 | virginica
(3 rows)
testdb=# \q
# psql -h postgres -U root testdb