LoginSignup
3
4

More than 3 years have passed since last update.

Dart x VSCode を Docker 上に構築 (1)

Last updated at Posted at 2019-04-30

Dart の開発環境も Docker で整えてしまうと楽です。今回の記事では、VSCodeもDockerに含めてみました。開発環境をまるごとDockerで管理できるので、管理がしやすいのでオススメです。

登場人物

Dockerとは

Linux上でコンテナーでアプリを動作させる環境です。アプリケーションとライブラリーを同一のコンテナーで固めて、使い回すことができます。
https://ja.wikipedia.org/wiki/Docker

VSCode

https://ja.wikipedia.org/wiki/Visual_Studio_Code
Microsoft製のEditorです。Dart Pluginを入れると、補間機能などが使えて便利です。

Code-Server

VSCodeをWebサービスとして動作させることができる凄いやつです。
https://github.com/cdr/code-server

環境を作ってみる

(1) dockerfile を書く

FROM ubuntu:18.04

RUN apt-get update
RUN apt-get install -y curl wget gnupg less lsof net-tools git apt-utils -y


# WORKDIR
RUN mkdir /works
WORKDIR /works

# DART
RUN apt-get install apt-transport-https
RUN sh -c 'curl https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -'
RUN sh -c 'curl https://storage.googleapis.com/download.dartlang.org/linux/debian/dart_stable.list > /etc/apt/sources.list.d/dart_stable.list'
RUN apt-get update
RUN apt-get install dart -y
ENV PATH="${PATH}:/usr/lib/dart/bin/"
ENV PATH="${PATH}:/root/.pub-cache/bin"

RUN pub global activate webdev
RUN pub global activate stagehand

#
# CODE-SERVER
RUN wget https://github.com/cdr/code-server/releases/download/1.939-vsc1.33.1/code-server1.939-vsc1.33.1-linux-x64.tar.gz
RUN tar xzf code-server1.939-vsc1.33.1-linux-x64.tar.gz -C ./ --strip-components 1

(2) docker image を走らせる

docker build -t dart_vscode .
docker run -p 8443:8443 -p 8080:8080 -it dart_vscode bash
# docker の中で
mkdir /works/w
/works/code-server /works/w --allow-http --no-auth

(3) and 'http://127.0.0.1:8443/' を ブラウザーで開く

root_page.jpg

試しに何か作ってみる

(1) Terminal -> New Terminal on VSCODE

(2) Terminal 上で以下を入力

root@8e5699b9caa4:/works/w# stagehand web-simple
root@8e5699b9caa4:/works/w# pub get
root@8e5699b9caa4:/works/w# webdev serve --hostname=0.0.0.0

(3) 'http://127.0.0.1:8080/' を ブラウザーで開く

sample_web.jpg

以上です。

Code-Serverがとても便利でしたね。
https://github.com/cdr/code-server

終わり。

今回のコードは以下にまとめました。
https://github.com/kyorohiro/dart-code-server

3
4
6

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
3
4