Skip to content

Running Code-Server in WSL2 #1868

Closed
Closed

Description

@chilcano
  • Web Browser: Chrome in Windows 10
  • Local OS: Windows 10
  • Remote OS: Ubuntu 20.04 and WSL2
  • Remote Architecture: NA
  • code-server --version: 3.4.1

I've tried to install Code-Server using the installation script and had this error:

Failed to connect to bus: No such file or directory

That is related to systemd and WSL2 (WSL and WSL2 don't support systemd, the PID 1 is Init).
Then, I've tried the Code-Server manual installation and every time I open WSL terminal I have to run:

$ code-server
info  Using config file ~/.config/code-server/config.yaml
info  Using user-data-dir ~/.local/share/code-server
info  code-server 3.4.1 44f7c2724827e526eeaa6c2c151c520f48a61222
info  HTTP server listening on http://0.0.0.0:8001
info      - Using password from ~/.config/code-server/config.yaml
info      - To disable use `--auth none`
info    - Not serving HTTPS

Is there any option to start Code-Server when Windows/WSL starts?

Is running Code-Server in Docker inside WSL2 an option?

Any help is welcome.
Regards.

Activity

  1. code-asher commented on Jul 7, 2020

    @code-asher
    Member

    I don't have any personal experience with autostarting services on WSL, but this looks like what you're looking for: https://superuser.com/questions/1343558/how-to-make-wsl-run-services-at-startup/1365978

    I'll close the issue but feel free to continue posting here.

  2. iHackFX commented on Aug 2, 2020

    @iHackFX

    How I run the code-server in WSL2 (Ubuntu 20.04) with port forwarding and SSL:

    1. Enable Self Signed Certificate without systemctl --user restart code-server
    2. Install certbot and get manualy SSL Certificate:
    sudo apt-get update
    sudo apt-get install software-properties-common
    sudo add-apt-repository universe
    sudo apt-get update
    sudo apt-get install certbot
    sudo certbot certonly --manual

    When he asked to create a file in the directory on the domain, I used MiniWeb HTTP server.
    3. I took the port forwarding .ps1 script for WSL2, and changed $ports to 443, and $addr to my local IPv4 (from ipconfig).
    4. Made a bat script to run everything at once. (Don't forget to change your data instead of <>)

    :: Getting administrator rights for a PowerShell script
    @echo off
    reg.exe query "HKU\S-1-5-19">nul 2>&1
    if %errorlevel% equ 1 goto UACPrompt
    Powershell.exe -executionpolicy remotesigned -File <path-to-script>
    cls
    C:\Windows\System32\bash.exe -c "code-server --cert '/etc/letsencrypt/live/<your-domain>/fullchain.pem' --cert-key '/etc/letsencrypt/live/<your-domain>/privkey.pem'"
    exit /b
    :UACPrompt
    mshta "vbscript:CreateObject("Shell.Application").ShellExecute("%~fs0", "", "", "runas", 1) & Close()"
    exit /b
    1. Forward port 443 on the router
    2. Run bat file.
    3. Profit

    If you need autorun

    Make the following .vbs file and place in Win-R -> shell:startup. (Don't forget to change your data instead of <>)

    Set WinScriptHost = CreateObject("WScript.Shell")
    WinScriptHost.Run Chr(34) & "<path-to-bat-file>" & Chr(34), 0
    Set WinScriptHost = Nothing
  3. bpmct commented on Aug 20, 2020

    @bpmct
    Member

    @iHackFX I love the detailed explanation!

    We just started using GitHub Discussions. Would you be able to share this on "Show and Tell" as well? I think it will help others with the same problem

  4. fearthecowboy commented on Sep 21, 2020

    @fearthecowboy

    FYI - I have a quick & dirty write up how I did code-server on WSL2:

    https://fearthecowboy.com/tutorial/2020/09/17/Code-Serrver-On-WSL.html

  5. fearthecowboy commented on Oct 21, 2020

    @fearthecowboy

    Another FYI -- I was playing around last night with WSL2 Docker Containers on Windows.

    It's actually really freaking easy to spin up code-server via the container; I'm working on some simple scripting to iron out the edges and should have that ready in a couple days.

    Turns out that it's really easy to add an automatic UPNP firewall port mapping, so that it can be exposed past the NAT without having to manually configure the router firewall, and by just mapping the one port thru the host, this gets stupid kinds of simple. I'm crafting a script for this, I'll be back in a day or two.

    # Quick & Dirty powershell script to use the containter with Docker & WSL2 containers.
    # Run this wherever you want the folder created and mapped to.
    
    # create a folder in the current directory
    cd (mkdir -ea 0 code-server)
    
    # create the '.config' and 'project' folders in the current location.
    mkdir -ea 0 .config,project
    
    # reformat the current folder as a unix-style path 
    $LOC = "/$(((pwd).path).substring(0,1).tolower()+((pwd).path).substring(1))" -replace '\\' ,'/' -replace ':',''
    
    # Run the docker image, map it back to port 8080 on the host, and map the .config and project folders  
    docker run -it --name code-server -p 127.0.0.1:8080:8080 -v "$LOC/.config:/home/coder/.config"  -v "$LOC/project:/home/coder/project"  codercom/code-server:latest -e PASSWORD=Hi-Mom!

    I may just roll the whole thing up into an extended docker image with a few parameters.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions