調査中
$ git clone https://github.com/microsoft/vscode-dev-containers.git
$ cd vscode-dev-containers/
$ git checkout v0.245.2
$ git branch
* (HEAD detached at v0.245.2)
main
$ cp -R vscode-dev-containers/containers/python-3 python-3
.
├── .devcontainer
│ ├── Dockerfile
│ └── devcontainer.json
└── .vscode
└── launch.json
FROM ubuntu:latest
RUN apt-get update && \
apt-get upgrade -y && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
RUN groupadd -g 1000 vscode && \
useradd -m -s /bin/bash -u 1000 -g 1000 vscode
{
"name": "Python 3",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
// Dockerfile に渡す変数
}
},
"customizations": {
"vscode": {
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/py-utils/bin/autopep8",
"python.formatting.blackPath": "/usr/local/py-utils/bin/black",
"python.formatting.yapfPath": "/usr/local/py-utils/bin/yapf",
"python.linting.banditPath": "/usr/local/py-utils/bin/bandit",
"python.linting.flake8Path": "/usr/local/py-utils/bin/flake8",
"python.linting.mypyPath": "/usr/local/py-utils/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/py-utils/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/py-utils/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/py-utils/bin/pylint"
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance"
]
}
},
"remoteUser": "vscode"
}
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python (Integrated Terminal)",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/test-project/hello.py",
"console": "integratedTerminal"
}
]
}
FROM ubuntu:latest
ARG DEBIAN_FRONTEND=noninteractive
ENV TZ=Asia/Tokyo
# update the ubuntu os image and install mandatory libs.
RUN apt-get update && apt-get upgrade -y && \
apt-get install -y build-essential libbz2-dev libdb-dev \
libreadline-dev libffi-dev libgdbm-dev liblzma-dev \
libncursesw5-dev libsqlite3-dev libssl-dev \
zlib1g-dev uuid-dev tk-dev \
sudo wget curl apt-utils locales lsb-release bash-completion && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
ARG PYTHON_VERSION
ARG PYTHON_REVISION
RUN wget https://www.python.org/ftp/python/${PYTHON_VERSION}.${PYTHON_REVISION}/Python-${PYTHON_VERSION}.${PYTHON_REVISION}.tgz && \
tar -xf Python-${PYTHON_VERSION}.${PYTHON_REVISION}.tgz && \
cd Python-${PYTHON_VERSION}.${PYTHON_REVISION} && \
./configure --enable-optimizations && \
make -j $(nproc) | tee build.log && \
sudo make altinstall
RUN /usr/local/bin/pip${PYTHON_VERSION} install --upgrade pip && \
/usr/local/bin/pip${PYTHON_VERSION} install autopep8 black yapf bandit flake8 mypy pycodestyle pydocstyle pylint
# Options
RUN apt-get update && \
apt-get install -y \
git vim tree htop iputils-ping iproute2 \
intel-mkl \
postgresql-client && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*
# for the numpy/scipy running on the intel processors.
RUN update-alternatives --set libblas.so.3-x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/libmkl_rt.so && \
update-alternatives --set libblas.so-x86_64-linux-gnu /usr/lib/x86_64-linux-gnu/libmkl_rt.so
# create vscode user
ARG USERNAME=vscode
ARG GROUPNAME=vscode
ARG USER_UID=1000
ARG USER_GID=$USER_UID
RUN groupadd -g 1000 ${GROUPNAME} && \
useradd -m -s /bin/bash -u ${USER_UID} -g ${USER_GID} ${USERNAME} && \
echo ${USERNAME} ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/${USERNAME} && \
chmod 0440 /etc/sudoers.d/${USERNAME} && \
localedef -f UTF-8 -i ja_JP ja_JP.UTF-8
# install poerty for vscode user
USER vscode
ARG WORKDIR
RUN curl -sSL https://raw.githubusercontent.com/python-poetry/poetry/master/install-poetry.py | python${PYTHON_VERSION} -
RUN echo "export PATH=/home/vscode/.local/bin:$PATH" >> /home/vscode/.bashrc
RUN /home/vscode/.local/bin/poetry completions bash | sudo tee /etc/bash_completion.d/poerty.bash-completion > /dev/null
RUN /home/vscode/.local/bin/poetry config cache-dir /workspaces/${WORKDIR}/.cache
~/docker/Python3-devcontainer/.devcontainer$ docker build --build-arg WORKDIR='Python3-devcontainer' --build-arg PYTHON_VERSION='3.11' --build-arg PYTHON_REVISION='3' .
~/docker/Python3-devcontainer/.devcontainer$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
<none> <none> 5f977a6bc71a 27 minutes ago 1.59GB
vsc-gpu-python-3-f89df00ce212f1edea4a2842bdfdc32a4605ac994cfe3e7b43ae00c8b9ba94c4-uid latest 065e9f88a9f2 31 hours ago 1.57GB
vsc-gpu-python-3-f89df00ce212f1edea4a2842bdfdc32a4605ac994cfe3e7b43ae00c8b9ba94c4 latest 2b55e70ce9d8 31 hours ago 1.57GB
vsc-python-3-7f7cf5bbb705da52cb06e373f5fd909d4cf3f9a244afc89dd274870056220d35-uid latest f6601e4d73ea 8 days ago 1.56GB
vsc-python-3-7f7cf5bbb705da52cb06e373f5fd909d4cf3f9a244afc89dd274870056220d35 latest a9d8df6a52d0 8 days ago 1.56GB
hello-world latest 9c7a54a9a43c 2 weeks ago 13.3kB
nvidia/cuda 11.6.2-base-ubuntu20.04 1aa90fd39a71 5 months ago 154MB
~/docker/Python3-devcontainer/.devcontainer$ docker run -it 5f977 /bin/bash
root@87851d9bfa78:/# python3
python3 python3.10 python3.11 python3.11-config
root@87851d9bfa78:/# which python3.10
/usr/bin/python3.10
root@87851d9bfa78:/# which python3.11
/usr/local/bin/python3.11
{
"name": "Python 3",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
"WORKDIR" : "Python3-devcontainer",
"PYTHON_VERSION" : "3.11",
"PYTHON_REVISION" : "3"
}
},
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python3.11",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/bin/autopep8",
"python.formatting.blackPath": "/usr/local/bin/black",
"python.formatting.yapfPath": "/usr/local/bin/yapf",
"python.linting.banditPath": "/usr/local/bin/bandit",
"python.linting.flake8Path": "/usr/local/bin/flake8",
"python.linting.mypyPath": "/usr/local/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/bin/pylint"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-azuretools.vscode-docker", // To avoid the vscode on the devcontaier recommends it.
"oderwat.indent-rainbow"
]
}
},
"runArgs" : ["--add-host=host.docker.internal:host-gateway"],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// 8888 : jupyter notebook
"forwardPorts": [8888],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}
version: "3"
services:
workspace:
build:
context: .
dockerfile: Dockerfile
volumes:
- ..:/workspace:cached
command: sleep infinity
ports:
- 8888:8888
extra_hosts:
- host.docker.internal:host-gateway
{
"name": "Python 3",
// "build": {
// "dockerfile": "Dockerfile",
// "context": "..",
// "args": {
// }
// },
"dockerComposeFile": "docker-compose.yml",
"service": "workspace",
"workspaceFolder": "/workspace",
"shutdownAction": "stopCompose",
// Configure tool-specific properties.
"customizations": {
// Configure properties specific to VS Code.
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/usr/local/bin/python3.11",
"python.linting.enabled": true,
"python.linting.pylintEnabled": true,
"python.formatting.autopep8Path": "/usr/local/bin/autopep8",
"python.formatting.blackPath": "/usr/local/bin/black",
"python.formatting.yapfPath": "/usr/local/bin/yapf",
"python.linting.banditPath": "/usr/local/bin/bandit",
"python.linting.flake8Path": "/usr/local/bin/flake8",
"python.linting.mypyPath": "/usr/local/bin/mypy",
"python.linting.pycodestylePath": "/usr/local/bin/pycodestyle",
"python.linting.pydocstylePath": "/usr/local/bin/pydocstyle",
"python.linting.pylintPath": "/usr/local/bin/pylint"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"ms-azuretools.vscode-docker", // To avoid the vscode on the devcontaier recommends it.
"oderwat.indent-rainbow"
]
}
},
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "pip3 install --user -r requirements.txt",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode"
}