Run VS Code on Docker

Purpose

Create a Docker container to run VS Code for use as a development environment. It will be executed as follows.

--VSCode starts as a GUI app when you start the container --The user who starts VS Code is specified when creating the container.

image.png

Prerequisites

It is assumed that the container image is created based on the article Running GUI application on Docker container (Japanese input).

Creating a Docker image

Dockerfile



FROM sabocla6/ubuntu_ui_jp

# ***********************************************
# install packages for xrdp, and do setting
# ***********************************************
RUN apt-get update && \
    DEBIAN_FRONTEND=noninteractive apt-get install -y \
        gnupg firefox supervisor

# ***********************************************
# prepare add user
# ***********************************************
RUN chmod u+s /usr/sbin/useradd \
    && chmod u+s /usr/sbin/groupadd \
    && chmod u+s /usr/sbin/chpasswd

COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN echo "ALL ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/ALL

# ***********************************************
# install vscode
# ***********************************************
ADD https://az764295.vo.msecnd.net/stable/ea3859d4ba2f3e577a159bc91e3074c5d85c0523/code_1.52.1-1608136922_amd64.deb /tmp/code.deb
RUN dpkg -i /tmp/code.deb

# ***********************************************
# copy entrypoint shell
# ***********************************************
COPY docker-entrypoint.sh /usr/local/bin/
RUN chmod +x /usr/local/bin/docker-entrypoint.sh
ENTRYPOINT ["docker-entrypoint.sh"]

docker-entrypoint.sh



#!/bin/bash -e

USER_ID=$(id -u)
GROUP_ID=$(id -g)
USER=${USER:-${DEFAULT_USER}}
GROUP=${GROUP:-${USER}}
PASSWD=${PASSWD:-${DEFAULT_PASSWD}}
NeW_USER=false

unset DEFAULT_USER DEFAULT_PASSWD

# Add group
echo ""
if [[ $GROUP_ID != "0" && ! $(getent group $GROUP) ]]; then
    echo "Create New Group GROUP_ID: $GROUP_ID GROUP: $GROUP"
    groupadd -g $GROUP_ID $GROUP
fi

# Add user
if [[ $USER_ID != "0" && ! $(getent passwd $USER) ]]; then
    echo "Create New User USER_ID: $USER_ID USER: $USER"
    export HOME=/home/$USER
    useradd -d ${HOME} -m -s /bin/bash -u $USER_ID -g $GROUP_ID -G 27 $USER
    NeW_USER=true
fi

# Set login user name
USER=$(whoami)
echo "USER: $USER"

# Set login password
echo "PASSWD: $PASSWD"
echo ${USER}:${PASSWD} | sudo chpasswd

# Revert permissions
sudo chmod u-s /usr/sbin/useradd
sudo chmod u-s /usr/sbin/groupadd
sudo chmod u-s /usr/sbin/chpasswd

unset PASSWD
if [[ "$@" = "" ]]; then
    exec /bin/bash
else 
    exec "$@"
fi

Build container image

sudo docker build ./ -t sabocl6/vscode

Start Docker container

Since there are many options that must be specified, start using docker-compose.

docker-compose.yml



version: "3.3"
services:
  devmachine:
    image: sabocla6/vscode
    volumes:
      - $HOME/.Xauthority:/root/.Xauthority
    user: "1000:1000"
    shm_size: '2G'
    network_mode: "host"
    privileged: true
    environment:
      USER: sabocla6
      PASSWD: passwd
      DISPLAY: $DISPLAY
    command: code -w

Start command


sudo docker-compose up

Related article

Run GUI application on Docker container (Japanese input) Run GUI application on Docker container

Reference article

For user creation, refer to Building a desktop environment where uid/gid can be specified and sudo can be used with Docker (XRDP).

Recommended Posts

Run VS Code on Docker
Run phpunit on Docker
Docker management with VS Code
Run openvpn on Docker (windows)
Run SSE (Server-Sent-Event) samples on docker
Steps to run docker on Mac
Run puppeteer-core on Heroku (Docker edition)
Run React on a Docker container
Run the AWS CLI on Docker
How to run JavaFX on Docker
Run GUI application on Docker container
Run PureScript on a Docker container
Getting Started with Docker with VS Code
Liberty on Docker
Run NordVPN on Docker (Windows) Ubuntu container
Run Embulk on Docker to convert files
Building a haskell environment with Docker + VS Code on Windows 10 Home
Hello World on Mac VS Code Java
Build Redmine code reading environment on Docker
Until you run apache on ubuntu on docker
Run Ubuntu + ROS with Docker on Mac
Redmine on Docker
Run GUI application on Docker container (Japanese input)
Run a Spring Boot project in VS Code
Run JSP Hello World with Tomcat on Docker
Using Gradle with VS Code, build Java → run
Connect with VS Code from a Windows client to Docker on another server
Run STS4 on Mac
Lombok with VS Code
Docker installation on CentOS 6
python notes on docker
Test run on rails
Run Pico with docker
Run PostgreSQL on Java
Install Docker on Manjaro
Run Payara with Docker
Run Processing on Ant
Run tiscamera on Ubuntu 18.04
M.S. docker on Windows
Docker installation on WSL2
Build Java development environment with VS Code on Mac
Run the Android emulator on Docker using Android Emulator Container Scripts
Build Java development environment with WSL2 Docker VS Code
Create a Java (Gradle) project with VS Code and develop it on a Docker container
Create a Java (Maven) project with VS Code and develop it on a Docker container
What is docker run -it?
Install Docker on Raspberry Pi
Install Docker on Windows 10 PRO
Until you run Quarkus and run docker image on Amazon ECS
Run TAO Core with Docker
Install Docker on Ubuntu Server 20.04
Memo that Azure Functions × Node.js × Typescript was run by Docker on the local virtual environment and debugged from VS Code
Try Docker on Windows 10 Home
Oracle Java 8 on Docker Ubuntu
Run lilypond on Docker on macOS Catalina to create sheet music
Format Ruby with VS Code
Hello World with VS Code!
Create a VS Code Plugin.
Run chromium-mir-kiosk on Ubuntu Core
Run Rails whenever with docker
Decomposing the Docker run command. .. ..