Update to use Python pre-built image
This commit is contained in:
@@ -3,60 +3,36 @@
|
|||||||
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
|
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
|
||||||
#-------------------------------------------------------------------------------------------------------------
|
#-------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
FROM python:3
|
# Update the VARIANT arg in devcontainer.json to pick a Python version: 3, 3.8, 3.7, 3.6
|
||||||
|
# To fully customize the contents of this image, use the following Dockerfile instead:
|
||||||
|
# https://github.com/microsoft/vscode-dev-containers/tree/v0.109.0/containers/python-3/.devcontainer/base.Dockerfile
|
||||||
|
ARG VARIANT=3
|
||||||
|
FROM mcr.microsoft.com/vscode/devcontainers/python:0-${VARIANT}
|
||||||
|
|
||||||
# Avoid warnings by switching to noninteractive
|
# [Optional] If your requirements rarely change, uncomment this section to add them to the image.
|
||||||
ENV DEBIAN_FRONTEND=noninteractive
|
#
|
||||||
|
|
||||||
# This Dockerfile adds a non-root user with sudo access. Use the "remoteUser"
|
|
||||||
# property in devcontainer.json to use it. On Linux, the container user's GID/UIDs
|
|
||||||
# will be updated to match your local UID/GID (when using the dockerFile property).
|
|
||||||
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
|
|
||||||
ARG USERNAME=vscode
|
|
||||||
ARG USER_UID=1000
|
|
||||||
ARG USER_GID=$USER_UID
|
|
||||||
|
|
||||||
ENV PIP_TARGET=/usr/local/share/pip-global
|
|
||||||
ENV PYTHONPATH=${PYTHONPATH}:${PIP_TARGET}
|
|
||||||
ENV PATH=${PATH}:${PIP_TARGET}/bin
|
|
||||||
|
|
||||||
# Uncomment the following COPY line and the corresponding lines in the `RUN` command if you wish to
|
|
||||||
# include your requirements in the image itself. It is suggested that you only do this if your
|
|
||||||
# requirements rarely (if ever) change.
|
|
||||||
# COPY requirements.txt /tmp/pip-tmp/
|
# COPY requirements.txt /tmp/pip-tmp/
|
||||||
|
# RUN pip3 --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
|
||||||
|
# && rm -rf /tmp/pip-tmp
|
||||||
|
|
||||||
# Configure apt and install packages
|
# [Optional] Create alternate global install location where the vscode user can write w/o sudo
|
||||||
RUN apt-get update \
|
ENV PIP_TARGET=/usr/local/pip-global
|
||||||
&& apt-get -y install --no-install-recommends apt-utils dialog 2>&1 \
|
ENV PYTHONPATH=${PIP_TARGET}:${PYTHONPATH}
|
||||||
#
|
ENV PATH=${PIP_TARGET}/bin:${PATH}
|
||||||
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed
|
RUN mkdir -p ${PIP_TARGET} \
|
||||||
&& apt-get -y install git iproute2 procps lsb-release \
|
&& chown vscode:root ${PIP_TARGET} \
|
||||||
#
|
&& export SNIPPET="if [ \"\$(stat -c '%U' ${PIP_TARGET})\" != \"vscode\" ]; then chown -R vscode:root ${PIP_TARGET}; fi" \
|
||||||
# Install pylint
|
&& echo "$SNIPPET" | tee -a /root/.bashrc >> /home/vscode/.bashrc \
|
||||||
&& pip --disable-pip-version-check --no-cache-dir install pylint \
|
&& echo "$SNIPPET" | tee -a /root/.zshrc >> /home/vscode/.zshrc
|
||||||
#
|
|
||||||
# Update Python environment based on requirements.txt
|
|
||||||
# && pip --disable-pip-version-check --no-cache-dir install -r /tmp/pip-tmp/requirements.txt \
|
|
||||||
# && rm -rf /tmp/pip-tmp \
|
|
||||||
#
|
|
||||||
# Create a non-root user to use if preferred - see https://aka.ms/vscode-remote/containers/non-root-user.
|
|
||||||
&& groupadd --gid $USER_GID $USERNAME \
|
|
||||||
&& useradd -s /bin/bash --uid $USER_UID --gid $USER_GID -m $USERNAME \
|
|
||||||
# [Optional] Add sudo support for the non-root user
|
|
||||||
&& apt-get install -y sudo \
|
|
||||||
&& echo $USERNAME ALL=\(root\) NOPASSWD:ALL > /etc/sudoers.d/$USERNAME\
|
|
||||||
&& chmod 0440 /etc/sudoers.d/$USERNAME \
|
|
||||||
#
|
|
||||||
# Create alternate global install location that both uses have rights to access
|
|
||||||
&& mkdir -p /usr/local/share/pip-global \
|
|
||||||
&& chown ${USERNAME}:root /usr/local/share/pip-global \
|
|
||||||
#
|
|
||||||
# Clean up
|
|
||||||
&& apt-get autoremove -y \
|
|
||||||
&& apt-get clean -y \
|
|
||||||
&& rm -rf /var/lib/apt/lists/*
|
|
||||||
|
|
||||||
# Switch back to dialog for any ad-hoc use of apt-get
|
|
||||||
ENV DEBIAN_FRONTEND=dialog
|
|
||||||
|
|
||||||
|
|
||||||
|
# [Optional] Uncomment this section to install additional packages.
|
||||||
|
#
|
||||||
|
# ENV DEBIAN_FRONTEND=noninteractive
|
||||||
|
# RUN apt-get update \
|
||||||
|
# && apt-get -y install --no-install-recommends <your-package-list-here> \
|
||||||
|
# #
|
||||||
|
# # Clean up
|
||||||
|
# && apt-get autoremove -y \
|
||||||
|
# && apt-get clean -y \
|
||||||
|
# && rm -rf /var/lib/apt/lists/*
|
||||||
|
# ENV DEBIAN_FRONTEND=dialog
|
||||||
|
|||||||
@@ -1,30 +1,42 @@
|
|||||||
{
|
{
|
||||||
"name": "Python 3",
|
"name": "Python 3 Sample",
|
||||||
"context": "..",
|
"build": {
|
||||||
"dockerFile": "Dockerfile",
|
"dockerfile": "Dockerfile",
|
||||||
|
"context": "..",
|
||||||
|
// Update 'VARIANT' to pick a Python version. Rebuild the container
|
||||||
|
// if it already exists to update. Available variants: 3, 3.6, 3.7, 3.8
|
||||||
|
"args": { "VARIANT": "3.7" }
|
||||||
|
},
|
||||||
|
|
||||||
// Use 'settings' to set *default* container specific settings.json values on container create.
|
// Set *default* container specific settings.json values on container create.
|
||||||
// You can edit these settings after create using File > Preferences > Settings > Remote.
|
|
||||||
"settings": {
|
"settings": {
|
||||||
"terminal.integrated.shell.linux": "/bin/bash",
|
"terminal.integrated.shell.linux": "/bin/bash",
|
||||||
"python.pythonPath": "/usr/local/bin/python",
|
"python.pythonPath": "/usr/local/bin/python",
|
||||||
"python.linting.enabled": true,
|
"python.linting.enabled": true,
|
||||||
"python.linting.pylintEnabled": true,
|
"python.linting.pylintEnabled": true,
|
||||||
"python.linting.pylintPath": "/usr/local/share/pip-global/bin/pylint"
|
"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",
|
||||||
|
"python.testing.pytestPath": "/usr/local/py-utils/bin/pytest"
|
||||||
},
|
},
|
||||||
|
|
||||||
// Use 'appPort' to create a container with published ports. If the port isn't working, be sure
|
// Add the IDs of extensions you want installed when the container is created.
|
||||||
// your server accepts connections from all interfaces (0.0.0.0 or '*'), not just localhost.
|
|
||||||
"appPort": [ 9000 ],
|
|
||||||
|
|
||||||
// Install flask and any other dependencies
|
|
||||||
"postCreateCommand": "pip install -r requirements.txt",
|
|
||||||
|
|
||||||
// Comment out next line to run as root
|
|
||||||
"remoteUser": "vscode",
|
|
||||||
|
|
||||||
// Add the IDs of extensions you want installed when the container is created in the array below.
|
|
||||||
"extensions": [
|
"extensions": [
|
||||||
"ms-python.python"
|
"ms-python.python"
|
||||||
]
|
],
|
||||||
|
|
||||||
|
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||||
|
"forwardPorts": [9000],
|
||||||
|
|
||||||
|
// Use 'postCreateCommand' to run commands after the container is created.
|
||||||
|
"postCreateCommand": "pip3 install -r requirements.txt",
|
||||||
|
|
||||||
|
// Uncomment to connect as a non-root user. See https://aka.ms/vscode-remote/containers/non-root.
|
||||||
|
"remoteUser": "vscode"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,9 +35,9 @@ Some things to try:
|
|||||||
- Try adding some code and check out the language features.
|
- Try adding some code and check out the language features.
|
||||||
2. **Terminal:**
|
2. **Terminal:**
|
||||||
- Press <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>\`</kbd> to open a terminal window.
|
- Press <kbd>ctrl</kbd>+<kbd>shift</kbd>+<kbd>\`</kbd> to open a terminal window.
|
||||||
- Type `python -m flask run --host 0.0.0.0 --port 9000 --no-debugger --no-reload` to run the app.
|
- Type `python -m flask run --port 9000 --no-debugger --no-reload` to run the app.
|
||||||
> **Note:** It is important to add `--host 0.0.0.0` when using `appPort` in `devcontainer.json` since this uses Docker to "publish" the port rather than forwarding it. It therefore will not work if the application only listens to localhost.
|
|
||||||
- Open a local browser and go to `http://localhost:9000` to see the running app.
|
- Open a local browser and go to `http://localhost:9000` to see the running app.
|
||||||
|
> **Tip:** If you use this container outside of VS Code via `docker run` with `-p 9000`, you may need to append `--host 0.0.0.0` to the command above. The `-p` option "publishes" the port rather than forwarding it. It therefore will not work if the application only listens to localhost. The `forwardPorts` property in `devcontainer.json` does not have this limitation, but you can use `appPort` to publish instead if you prefer.
|
||||||
3. **Build, Run, and Debug:**
|
3. **Build, Run, and Debug:**
|
||||||
- Open `app.py`
|
- Open `app.py`
|
||||||
- Add a breakpoint (e.g. on line 9).
|
- Add a breakpoint (e.g. on line 9).
|
||||||
|
|||||||
Reference in New Issue
Block a user