[Docker & Tools] Dev Containers with Visual Studio Code
Go ahead and install the Remote - Containers extension.
This takes everything one step further: you can actually set up someone's editor for them when they open your project. You can change settings, add extensions, define debugging, and control the container environment with the remote extension and dev containers. Let's go ahead and give it a shot!
Make a folder within your static-app project called .devcontainer
. In there we'll put two files. The first one is the Dockerfile where we'll just set up our dev environment.
FROM node:12-stretch
RUN npm install -g eslint prettier
Just need the tools and environment, don't actually need to build anything or put the code in there. Visual Studio Code will handle that automatically. Next make a file inside .devcontainer
called devcontainer.json
. The folder name has leading .
, the the JSON file does not.
{
"name": "Frontend Masters Sample",
"dockerFile": "Dockerfile",
"appPort": [3000],
"runArgs": ["-u", "node"],
"settings": {
"workbench.colorTheme": "Night Owl",
"terminal.integrated.shell.linux": "/bin/bash"
},
"postCreateCommand": "npm install",
"extensions": [
"sdras.night-owl",
"dbaeumer.vscode-eslint",
"esbenp.prettier-vscode"
]
}
From here, close Visual Studio Code and then reopen the project again. You should see a little prompt asking you if you want to re-open the project in a container. Click yes! If you miss that prompt, click the (normally green) button in the bottom left of VSCode that look sort like ><
but shoved together. It should have an option to open this project in a dev container.
NOTE: if you're on Windows and you're following along with WSL, you'll have to get the project out of WSL before it'll let you re-open it in a container. This will hopefully be a smoother experience in the future. To get into Windows from WSL, click the same ><
logo in the bottom left and say open in Windows. From there the above instructions should work.
Couple of key things here:
- We can have two different Dockerfiles for dev and production. We can have one. I generally have two unless they overlap so much they're basically the same.
- We're setting up our colleagues for success by making sure everyone has the correct extensions installed for dev. In this case, I added Prettier and ESLint to my team's environment so they can have instant feedback when they're working.
- We can add settings to their environment (like formatting on save) so that everything just works the same for everyone. No worries: your team can override any of this if it's not for them.
This whole workflow works for VSCode users only so not everyone will get to take apart of the magic. However, at the end of it all, it's just a container for development environments and they have the Dockerfile. They can still build and run that via the techniques above!
From here you can get as complicated as you need, setting up memory dumps, tracing, and the like. I leave that as an exercise for you (as I'm not the most knowledgeable on how to do it) but whatever you can do with a bash script can be done by Docker for you!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
2021-08-09 [Unit testing + Jest] Use a Test Object Factory utils/generate
2019-08-09 [Algorithm] Step Back From the Tail
2017-08-09 [Web Security] Create a hash salt password which can stored in DB
2017-08-09 [Angular] Stagger animation v4.3.3
2016-08-09 [ES6] ES6 Parameter Object Destructuring with Required Values
2014-08-09 [Backbone] Customzing Backbone
2014-08-09 [Backbone] Working with forms