Hello,
I have been using VS Code for some years and recently started using Docker, but I am not an expert in IT infrastructure so I would like to know if it is possible to literally have VS Code and the elements required to use notebooks (Ipykernel, Python, etc) installed in a container, so that I can directly use it anywhere.
The reason for this approach is that I am working with some data hosted in an offline server, and the only way to work in there is through the packages and modules you install in a container. I can already use Jupyter notebook as it seems to be quite simple to get - just including python, its packages, and Jupyter notebook in the container.
However, I really am not a fan of Jupyter and I would love to set up a way to have VS Code run on that server. I would greatly appreciate any tips that anyone could give :)
Thanks a lot!
Best regards,
Red muffin
Goal
Having multiple containers with different vscode instances.
Example: I want one container with a vscode with the necessary extensions (and dependecies) to do web development, other container to do back-end development, and other to do data-science development. This will avoid having tons of extensions in the same VScode instance, wich sometimes, causes conflicts.
As far as i know, this can be done accessing via browser pointing to a port of the container running VScode right? Can i access without the need of browser? This is because i use a lot keyshortcuts and i'm afraid they don't work if use VScode via browser. Also, is the performance a concern or will it run smoothly?
Some references
site A
site B
If you have other references other than the ones i provided, please share.
Videos
I'm using a local docker container to manage dependencies and requirements while developing a software. I'm using VSCode as my code editor. The problem is that my VSCode doesn't have access to the libraries (and headers), as they're installed inside the docker.
I've found out one can use an extension that will automatically install VSCode server on the docker, and my local VSCode will let me code using that server. The problem is that not only it requires to install the server, it also requires installing all the local extensions on the remote server (if I want to use them). That makes sense in cases of people developing on an actual remote server, but in my case, it means I'd have to have each extension installed twice on my machine, wasting space.
I've also thought about using volume mapped to my local workfolder (or something like that) to let me access the libraries (or at least headers) installed there, but I'm not sure how well would that work and how exactly should I go about doing that (I'm worried about shadowing/overwritting the default installed libraries on the docker if I map the volume there). Or alternatively, sharing the local and docker's extensions this way, but I think that could go very wrong.
Is there a good solution? What's the optimal way to handle this?
Has anyone tried developing (ideally python) inside a docker container? Im relatively new to development.
Just wondering what others think some pros/cons might be.
https://code.visualstudio.com/docs/devcontainers/containers
Hello guys. I am new to docker and I am given a complete project in FastAPI complete with docker-compose to work with. I am learning in the process. Currently, I'm just using docker-compose up , putting the .py files I want to run and test in the Dockerfile's CMD field and re-running docker-compose, which is a painstakingly repetitive process. Also I am using vscode and it keeps notifyingme that it can't find a python interpreter. So I was wondering if it was possible to use vscode inside the docker environment and run files individually without the need to put them in Dockerfile first. Is there any guide which I can follow? I am using Docker for windows btw.
Any help or guidance would be great. Thanks.
Edit: Thank you u/Pyodoo for the Silver!
Regarding visual studio code development container, am I right to understand that the docker container interacts with the source code you're working on by remotely accessing it? And the dependencies required to develope are stored in the docker container.
As seen here: https://docs.microsoft.com/en-us/learn/modules/use-docker-container-dev-env-vs-code/3-use-as-development-environment
Thank you
Created a post to summarize the basics and share some potentials Dev Containers has.
https://tomhudak.github.io/blog/2021-11-16-containerize-your-development-environment-with-visual-studio-code/
Hi!
Where I work we're starting to use containers and Kubernetes to deploy apps.
I've been reading about it but still have some thins that I don't understand.
This is my situation:
-
working on vs code on my windows pc
-
connect to a ubuntu machine where I develop in python
-
installed docker on the ubuntu
I've created a development environment as said in https://code.visualstudio.com/docs/devcontainers/create-dev-container where I installed all the packages I needed.
I developed a small app just for testing and have no errors.
Questions:
-
How do I deliver the app to the Kubernetes guy?
-
Do I have to make a Dockerfile?
-
Is it better to create a container through the json file or with a Dockerfile?
-
I have some setup variables to change user/pass/servers and some other things that can change depending of the situation. Usually I create a .env file from where I read the values. Can the Kubernetes guy replace that file when deploying the container or do I need to put that all in environment variables?
Any help or point to help would be greatly appreciated! :)
TY!
Hey,
I would like to dev a VS code extension inside of a Docker container. I am still unfamiliar with Docker as well a developing an extension. This is my first real side project.
I was wondering if you could enlighten me a little on how to best approach this. Originally, what I wanted to try is to do everything on the container instance and have absolutely nothing installed on my computer. Nonetheless, the more I explore, the more it seems overly complicated.
My idea was to therefore install Node.js and yo on my local machine using the following:
npm install --global yo generator-code
yo code
After the structure is created, I could then create a Docker image to start developing inside the container.
I have a few questions:
-
What do you guys think about this process, could I have done it without using the yo library ?
-
Any base image you recommend, I was trying node:14 but it wouldn't create the expected workdir usr/src/app
-
Any other tips or recommendations ?
Thank you so much in advance !
Hello everyone,
I have installed docker on my local machine (Ubuntu). Then created 2 docker containers, one for Odoo, the other for Postgresql.
In my vscode terminal, I added the current user to the docker group successfully. And I can run "docker compose up -d" without sudo. But I still can't access the container in vscode.
I'm using the extension: Dev Containers by Microsoft. When I try "Dev Containers: open folder in container", I get the following message in a window:
Current user does not have permission to run 'docker'. Try adding the user to the 'docker' group.
Has anyone faced this issue before? And how to solve it?
Thanks in advance...
Like most developers, I like to keep my workstation clean. This is a quick rundown of how you can have a working dev setup, specifically for web apps, on Windows 10, Mac OSX and Linux. Sorry BSDs...
Things you need
-
Docker
-
VS Code
-
An SSH client (Optional)
You probably already have the first two installed, or know how to install it. The last requirement is also available on most Linux distros and MacOS out of the box.
Linux users are required to add their regular user to the Docker user group:
$ sudo usermod -aG docker $USER
For this change to take effect you need to log out and sign back in.
Why use Remote - Container?
Remote Container extension allows you to focus on your ideas and not the environment. Start developing directly within a container, with a fully functional editor, i.e, VS Code. Its integrated shell also allows you to use the container as a functional Linux environment. Install the extension by visiting this page.
You can start by simply pulling a Docker image of your choice, spin up a container, and use VS Code to start editing files within that container.
No need to install dozens of packages on your host system, neither will you have several dozen Docker images cluttering your workspace as you tweak and fiddle with Dockerfiles. Only when you have a working prototype of your app, should you consider creating a Dockerfile to package it.
You can even use base OS images like Alpine or Ubuntu, if you want.
Getting started
-
With the extension installed, let us create a container named dev0using the official Node.js image from Docker Hub:
$ docker run -dit --name dev0 -p 3000:3000 node
2. Next, open VS Code, and if you have the extension installed you will see a small green icon at the bottom left corner of the screen. 3. It will show you various options, let's select "Attach to Running Container" option:
This is followed by selecting the proper container name. In our case, this is dev0.
Your New Environment
This is where a new instance of the VS Code will open up. If you now open the integrated terminal (use keyboard shortcut Ctrl+`) this will drop you in a shell inside the container.
Since we are using a Node.js container, it already has node and NPM available for us, let us start a small project:
$ mkdir app $ npm init ## Keep hitting Return to accept the defaults and reply 'yes' when prompted $ npm install --save express
Create a file 'index.js' in here, and try out this simple "Hello, world" snippet that uses express framework:
const express = require('express')
const app = express()
const port = 3000
app.get('/', (req, res) => res.send('Hello World!'))
app.listen(port, () => console.log(`Example app listening on port ${port}!`))Using the integrated terminal, run the above code:
$ node index.js
The result can be seen at http://localhost:3000/ . You can now continue to work on your app and use localhost:3000 to access its contents.
If you want to open a new directory /foo/bar, run the following command inside the container, using VS Code integrated terminal:
$ code /foo/bar
This opens another instance of VS Code with /foo/bar. You can invoke VS Code from inside the container dev0!
Side Note
If you open a VS code workspace in a specific folder, say, /root/app directory, then delete the container, and create a new one to connect via VS Code, it will try to reopen /root/app directory.
Since the directory no longer exists, the remote session will be rendered unusable.
At the time of this writing, the extension of the remote container is still in preview, and hopefully, this bug will be resolved in future updates. For now, you can mitigate this issue by creating whatever directory VS Code is expecting, like, /root/app:
$ docker exec dev0 bash -c "mkdir -p /root/app"
It's not the tidiest solution, but it does circumvent the issue.
Bind Mounts
If you have a current project that you want to test inside a running container, you can do that using VS Code as well. The same extension can allow you to setup bind mounts so you can access parts of the host filesystem within the container.
For example, if you have a directory ~/Desktop/app on my host system, you can start by:
-
Clicking on the same green icon and then selecting "Remote-Container: Open Folder in container..."
-
Selecting that folder, and then picking a container image offered by Microsoft will allow you to open those file inside a newly created container.
-
When prompted, give Docker the necessary permissions to access the host file system.
-
Select one of the many container images offered by VS Code.
-
Start hacking!
There are a few caveats, however:
-
You have a limited set of container images offered by VS Code itself, to use with the bind mount feature.
-
If you are on Windows, you need to tweak your VS Code to use Unix style line endings (a.k.a LF) and a compatible character encoding like UTF-8 or ASCII.
Moving Forward
If the above workflow appeals to you, there is more! The extension is still in preview and it will become more functionally stable with each commit that it gets.
Send pull requests, report issues and don't forget to have fun!
This article was originally published onhttps://appfleet.com/blog/minimal-dev-environment-vs-code-docker-3/ and has been authorized by Appfleet for a republish.
I plan on moving my dev environment to a docker container and using VSCode with the Remote Explorer extension to work on my project remotely. Are there any docker images already created just for this? Or should I just use a node image?
Thanks
Hi.
I recently joined a project with collaborators where we use docker. I'm the only one using vscode in the team, and this my first time working with docker (though I'm getting used to it and it's amazing).
I see lots of ways to add development container configurations with vscode, but I'm not sure how to open a container that has a pre-existing Dockerfile that someone else created in vscode. If I were to modify that Dockerfile I would need permission too.
Frankly there are too many options for ways too add configurations I'm at a loss what to do.
Any help is appreciated:)
Edit: The solution was in the documentation as it should have. It seems I was confused with what the documentation was saying and the solution slipped through my attention here. Reading the replies has helped me learn about docker tho. Thank you all for your help:)
what do you mean by “open a container”? I suspect you are missing some understanding about docker. perhaps you should start there
I'm having a hard time understanding what you want to do specifically. Do you want to work with a repository inside a docker container to have a common development environment that is always the same regardless of the host system?
In that case you simply follow this guide: https://code.visualstudio.com/docs/remote/containers
I used to have the Docker (from Microsoft) and Docker DX (from Docker) extensions installed in VS Code, but I got a notice that they were being replaced with Container Tools and Dev Containers (both from Microsoft) going forward.
Is that correct? I have Docker and Docker DX disabled. Should I just uninstall them?
I really only use the extensions so that any errors are shown in my Dockerfile and docker-compose.yaml files.