You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Let's create a bare-bones devcontainer for our python project. Create a new folder:
13
14
14
15
```bash
@@ -31,6 +32,7 @@ Now populate it with the following:
31
32
```
32
33
This will create a new devcontainer called "Research Environment" that will use the Dockerfile in the parent directory. It will also forward port 8888 to the host machine.
33
34
35
+
## Better
34
36
This is very basic. We don't have much functionality here at all. And how do we even access the actual jupyter lab server? We don't even have the python extension installed in the container! We would also find that any changes to the the stuff inside the container would not be reflected in the host machine. So let's make our experience more enjoyable.
35
37
36
38
```json
@@ -83,13 +85,13 @@ Now we have **a lot** more functionality!
83
85
84
86
Let's look at exactly what is going on here:
85
87
86
-
1.Top-level configuration:
88
+
**Top-level configuration**
87
89
```json
88
90
"name": "Research Environment",
89
91
```
90
92
This simply names your development container for easy identification.
91
93
92
-
2.Build configuration:
94
+
**Build configuration**
93
95
```json
94
96
"build": {
95
97
"dockerfile": "../Dockerfile",
@@ -100,15 +102,15 @@ This tells VS Code how to build the container:
100
102
-`dockerfile`: Points to a Dockerfile one directory up from the devcontainer.json
101
103
-`context`: Sets the build context to the parent directory - what stuff to include in the build
102
104
103
-
3.Features section:
105
+
**Features section**
104
106
```json
105
107
"features": {
106
108
"ghcr.io/devcontainers/features/git:1": {}
107
109
}
108
110
```
109
111
This adds additional tools to your container. Here, it's installing Git from the GitHub Container Registry.
110
112
111
-
4.VS Code Customizations:
113
+
**VS Code Customizations**
112
114
```json
113
115
"customizations": {
114
116
"vscode": {
@@ -118,43 +120,47 @@ This adds additional tools to your container. Here, it's installing Git from the
118
120
}
119
121
```
120
122
This configures VS Code-specific settings:
123
+
121
124
- Extensions installed automatically:
122
-
- Python extension
123
-
- Pylance (Python language server)
124
-
- Black formatter
125
-
- Jupyter notebook support
126
-
- GitHub Copilot
125
+
- Python extension
126
+
- Pylance (Python language server)
127
+
- Black formatter
128
+
- Jupyter notebook support
129
+
- GitHub Copilot
130
+
127
131
- VS Code settings configured:
128
-
- Sets Python interpreter path
129
-
- Enables linting
130
-
- Uses Black for formatting
131
-
- Enables format-on-save
132
-
- Sets a line length ruler at 88 characters (Black's default)
132
+
- Sets Python interpreter path
133
+
- Enables linting
134
+
- Uses Black for formatting
135
+
- Enables format-on-save
136
+
- Sets a line length ruler at 88 characters (Black's default)
133
137
134
138
We can add other dev tools here like mypy or itools or flake8.
135
139
136
-
1.Port Forwarding:
140
+
**Port Forwarding**
137
141
```json
138
142
"forwardPorts": [8888]
139
143
```
140
144
Makes port 8888 (commonly used for Jupyter notebooks) available on your local machine.
0 commit comments