A Docker container image for MS Visual Studio Code and CDR code-server.
App | Pros | Cons |
---|---|---|
VS Code | Full IDE with extensions | Desktop app |
code-server | Web app | Installing MS extensions violates Term-of-Use (ToU) |
- Headless server: run app with X in a remote server.
- Reproducible science: pack all tools and data needed for a experiment along with the IDE in order to re-run it or do a step-by-step execution.
- Cybersecurity: you can run and test apps and libraries within a secure container without affecting your host system.
- Edit, compile and run any source code with just attaching the folder to a Docker volume.
- Distribute your app image along with a full IDE version with all components (compiler, debugger, extensiones, etc) already installed.
- Change some packages installed in this image in order to switch to other languages (Python, R, Javascript, etc).
- In Windows, you may want to run, test or debug your app against Linux libraries without using WSL.
Word of caution: this image is intended as a Proof-of-Concept (PoC) for educational purposes only.
- Docker
- Windows: install MobaXterm to run the X11 server
- Mac: install XQuartz
- Terminal: you may use MobaXterm or any other app
As of April 2022, the image comes with the following software installed:
Software apps or packages | Version |
---|---|
VS Code | 1.66 |
code-server | 4.2.0 |
build-essential (gcc , g++ , make ) |
12.4 |
C/C++ IntelliSense, debugging, and code browsing extension | 1.9.7 |
Move to a specific folder/directory, for instance c:\temp
in Windows or \tmp
in Mac, and type the following:
git clone http://github.com/mcolebrook/code-con
cd code-con
docker build -t code-con .
Or just invoke image mcolebrook/code-con
from Docker Hub in the following section.
Note: we consider that you cloned the project in
c:\temp
. If not, please change directory accordingly. Besides, please remember to put the right IP address (fill in theDISPLAY
option).
docker run --rm -it --name code-con --hostname linux \
--cap-add=SYS_ADMIN \
-p 8080:8080 -e DISPLAY=___.___.___.___:0.0 \
--mount type=bind,source=/c/temp/code-con/settings/vscode-settings.json,target=/home/user/.config/Code/User/settings.json \
--mount type=bind,source=/c/temp/code-con/settings/code-server-settings.json,target=/home/user/.local/share/code-server/User/settings.json \
-v /c/temp/code-con/src:/home/user/src \
mcolebrook/code-con
Note: we consider that you cloned the project in
\tmp
. If not, please change directory accordingly.
xhost +
docker run --rm -it --name code-con --hostname linux \
--cap-add=SYS_ADMIN \
-p 8080:8080 -e DISPLAY=host.docker.internal:0.0 \
--mount type=bind,source=/tmp/code-con/settings/vscode-settings.json,target=/home/user/.config/Code/User/settings.json \
--mount type=bind,source=/tmp/code-con/settings/code-server-settings.json,target=/home/user/.local/share/code-server/User/settings.json \
-v /tmp/code-con/src:/home/user/src \
mcolebrook/code-con
If you get any trouble, please refer to the following blog [1].
vscode.sh
If you want to start editing inside the default folder location (src
) just type:
vscode.sh .
code-server.sh
Then, go to the browser and type: <YOUR IP ADDRESS>:8080
(Windows) or localhost:8080
(Mac)
If you want to start editing inside the default folder location (src
) just type:
code-server.sh .
Note: If you are under Windows 8.x, get the right IP address using:
docker-machine ip
- VS Code debugging
helloworld
in Windows
- code-server running
helloworld
in Mac
@software{Colebrook_code-con_2021,
title = {{code-con: a Docker image of VS Code and CDR code-server}},
author = {Colebrook, Marcos},
year = {2021}
url = {https://github.com/mcolebrook/code-con}
}
This work has been developed within project UDIGEN, grant RTC-2017-6471-1 funded by MCIN/AEI/10.13039/501100011033 and by “ERDF A way of making Europe”.
This project has been developed thanks to previous work done by: Binal Patel (@caesarnine), Jess Frazelle (@jessfraz), Christopher Miles (cmiles74), Coder, Microsoft.
[1] Mamykin K, How to run dockerized X Windows apps on macOS.
[2] Docker Inc., Best practices for writing Dockerfiles.
[3] Vass T (2019), Intro Guide to Dockerfile Best Practices.
[4] Noring C (2019), Improve your Dockerfile, best practices.
[5] Nüst D, Sochat V, Marwick B, Eglen SJ, Head T, Hirst T, Evans BD (2020), Ten simple rules for writing Dockerfiles for reproducible data science, PLOS Computational Biology 16(11): e1008316.