LoginSignup
1
2

More than 3 years have passed since last update.

Ubuntu on WSL でCode-Serverを起動する

Last updated at Posted at 2019-11-22

Ubuntu on WSL でcode-serverを起動する

Windows10のWSL(Windows Subsystem for Linux)のUbuntuにDockerをインストールして、Docker Imageのcode-serverを起動します。

【参考】code-server

開発環境

バージョン
OS Windows 10(1903)
Ubuntu 18.04 LTS
Docker-ce 17.09.0

※ Windows10でWSLのセットアップと、Ubuntuのインストール方法は省略します。

UbuntuにDocker-ce(17.09.0)をインストール

いろいろと試した結果、最新のDockerではcode-serverが起動しないため、Dockerのバージョンは「17.09.0」としました。

Ubuntuを「管理者として実行」で開き、以下を実行(少々時間がかかる)

> sudo apt-get update
> sudo apt -y upgrade

さらに以下を実行(少々時間がかかる)

> curl -O https://download.docker.com/linux/debian/dists/stretch/pool/stable/amd64/docker-ce_17.09.0~ce-0~debian_amd64.deb
> sudo apt install libltdl7 -y
> sudo dpkg -i docker-ce_17.09.0\~ce-0\~debian_amd64.deb

ここでUbuntuを閉じ、PowerShell「管理者として実行」で開き、以下を実行し、WSLを再起動する。

> Restart-Service LxssManager

再びUbuntuを「管理者として実行」で開き、以下を実行し、dockerのバージョンを確認

> docker -v
Docker version 17.09.0-ce, build afdb6d4

dockerサービスを開始する。

> sudo service docker start

dockerサービスの起動を確認する。
「Docker is running」と表示される。
「Docker is not running」となる場合があるが、再びサービス開始を行うか、Ubuntuを再起動してからサービス開始を行うなど、「Docker is running」が確認できるまで頑張る。

> sudo service docker status
 * Docker is running

Docker起動確認

dockerのHelloWorldを実行する。
「Hello from Docker!」が表示されればOK。

> sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete                                                                                             Digest: sha256:c3b4ada4687bbaa170745b3e4dd8ac3f194ca95b2d0518b417fb47e5879d9b5f
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/

code-serverを起動する

以下を実行しcode-serverを起動する。


> sudo docker run -it --user root -p 127.0.0.1:8080:8080 -v "${HOME}/.local/share/code-server:/home/coder/.local/share/code-server" -v "$PWD:/home/coder/project" codercom/code-server:v2 --auth none

code-serverのサイトに書かれている起動方法では、「permission denied」が出てcode-serverが起動出来なかったため「--user root」を追加している。
※ あと「sudo」「--auth none」も追加している。

以下のようになればcode-server起動成功。

sudo docker run -it --user root -p 127.0.0.1:8080:8080 -v "${HOME}/.local/share/code-server:/home/coder/.local/share/code-server" -v "$PWD:/home/coder/project" codercom/code-server:v2 --auth none
Unable to find image 'codercom/code-server:v2' locally
v2: Pulling from codercom/code-server
7ddbc47eeb70: Pull complete
c1bbdc448b72: Pull complete

...

Digest: sha256:7f0aae14c17bedf7b716817ce4d0f16f237eb161cf99a5aeb273427e5133944f
Status: Downloaded newer image for codercom/code-server:v2
info  Server listening on http://0.0.0.0:8080
info    - No authentication
info    - Not serving HTTPS

ブラウザからVSCodeを開く

ブラウザを開き「http://localhost:8080」にアクセスする。

ブラウザで起動.png

次回予定

code-serverのVSCodeを少しいじって見る。そして、VSCodeの拡張機能をインストールしてみる。

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2