Create a simple Python development environment with VSCode & Docker Desktop

The new Mac finally arrived! I want the guy I bought by hitting a lot to stay as beautiful as possible ... !! In that case, even if it is a personal development environment, the container is still good, so this time I will create a simple Python development environment combined with Docker Desktop using Remote-Containers which is an extension of VS Code.

I'm not a professional engineer, so it's not very specialized. Anyway, if the Python code I wrote in VS Code can be executed quickly on the container, it will be a character.

usage environment macOS Catalina ver 10.15.7 Visual Studio Code 1.51.0 Docker Desktop(stable) 2.5.0.0

Install Visual Studio Code and Docker Desktop

Visual Studio Code https://azure.microsoft.com/ja-jp/products/visual-studio-code/

Docker Desktop https://www.docker.com/products/docker-desktop

Install Remote -Containers in Visual Studio Code

Search for and install Remote-containers from the Visual Studio Code extension. If the installation is successful, you will see this green icon in the lower left corner of VS Code. VScode-Docker-for-MacPython.png

Get a Python Docker image

Execute the following code in any directory from the Mac terminal

#Get Docker image for Python3
docker pull python:3

#Check if you can get the Docker image
docker images
#result
#REPOSITORY               TAG                 IMAGE ID            CREATED             SIZE
#python                   3                   768307cdb999        3 days ago          886MB

You can also check the Python 3 image from the Docker Desktop dashboard. _2020-11-07_20.53.09.png

Create & launch Docker container

Create & start a container from the acquired Docker image. Execute the following command from the terminal

#Creating a container&Start-up
docker run -d -it python:3

#Checking the container
docker ps 
#result
#CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
#bf6e8b53da45        python:3            "python3"           7 seconds ago       Up 6 seconds                            strange_williamson

You can also create and launch it by clicking the "Run" button from the dashboard. Untitled.png

Connect to a container from VS Code using Remote-Containers

Click this button at the bottom left of the VS Code screen VScode-Docker-for-MacPython.png

Select "Attach to Running Container ..." from the pop-up displayed at the top of the screen Untitled 1.png

Since the running container is displayed, click the container you want to use. This will connect you to the container environment you want to develop. Untitled 2.png

Then click "Open Folder" from File Explorer and select the directory where you want to put your code. Untitled 3.png

Select any directory and click "OK" Untitled 4.png

Finally, click "Terminal"-> "New Terminal" from the VS Code menu.

An environment where code written in VS Code like this can be executed quickly on a Docker container is completed. _2020-11-07_21.34.38.png

in conclusion

This time I connected to a container that has already been started, but if you prepare a Dockerfile, it will also create a container, so if you are interested, please try various things.

Anyway, it seems that I can live happily with a beautiful Mac for a long time.

Reference article

https://blog.hiros-dot.net/?p=10059 https://www.keisuke69.net/entry/2020/06/04/145719

Recommended Posts

Create a simple Python development environment with VSCode & Docker Desktop
Create a simple Python development environment with VS Code and Docker
[Python] Build a Django development environment with Docker
Create a C ++ and Python execution environment with WSL2 + Docker + VSCode
Create a python development environment with vagrant + ansible + fabric
Create a virtual environment with Python!
Build a local development environment with WSL + Docker Desktop for Windows + docker-lambda + Python
[Python] Create a virtual environment with Anaconda
Create Python + uWSGI + Nginx environment with Docker
Create a Python execution environment for Windows with VScode + Remote WSL
Create a development environment for Go + MySQL + nginx with Docker (docker-compose)
Create a Python environment
Create a virtual environment with conda in Python
Start a simple Python web server with Docker
Create a python3 build environment with Sublime Text3
Create Nginx + uWSGI + Python (Django) environment with docker
[Docker] Create a jupyterLab (python) environment in 3 minutes!
Create a Python virtual development environment on Windows
Get a quick Python development environment with Poetry
Prepare python3 environment with Docker
Create a directory with python
Create a comfortable Python 3 (Anaconda) development environment on windows
Build a machine learning application development environment with Python
Create a Layer for AWS Lambda Python with Docker
QGIS3 Python plugin development environment construction with VSCode (macOS)
Build a development environment with Poetry Django Docker Pycharm
Create a Python development environment on OS X Lion
Set up a Python development environment with Sublime Text 2
Build a Django development environment with Docker! (Docker-compose / Django / postgreSQL / nginx)
Create a Python (pyenv / virtualenv) development environment on Mac (Homebrew)
Set up a Python development environment with Visual Studio Code
[Memo] Build a development environment for Django + Nuxt.js with Docker
Create a Python environment on Mac (2017/4)
Build Mysql + Python environment with docker
Building a virtual environment with Python 3
[Django] Build a Django container (Docker) development environment quickly with PyCharm
Build a comfortable development environment with VSCode x Remote Development x Pipenv
Create a python environment on centos
Create a simple video analysis tool with python wxpython + openCV
Get a clean Python development environment with pyenv + pipx + Poetry
How to build a python2.7 series development environment with Vagrant
Create a Todo app with Django ① Build an environment with Docker
Prepare Python development environment with Atom
Rebuild Django's development environment with Docker! !! !! !!
Application development with Docker + Python + Flask
I wrote a script to create a Twitter Bot development environment quickly with AWS Lambda + Python 2.7
I made a development environment for Django 3.0 with Docker, Docker-compose, Poetry
Create a USB boot Ubuntu with a Python environment for data analysis
[DynamoDB] [Docker] Build a development environment for DynamoDB and Django with docker-compose
[Pyenv] Building a python environment with ubuntu 16.04
Create a Python function decorator with Class
Creating a simple PowerPoint file with Python
Easily build a development environment with Laragon
[Development environment] Python with Xcode [With screen transition]
Build a blockchain with Python ① Create a class
Create a dummy image with Python + PIL.
Create a python environment on your Mac
Create a simple GUI app in Python
Let's create a free group with Python
Building a Python 3.6 environment with Windows + PowerShell
[Python] Create a Batch environment using AWS-CDK