ITエンジニア 環境構築

windowsで開発環境を構築する

こんにちは、ともです。

最近フルスタックエンジニアというキーワードを聞きます。Webアプリ開発のみではなく、ミドルウェア、インフラ、ネットワークといった幅広いITの技術を持つ人材が必要とされています。

今回はwindowsの開発環境構築を勉強することでミドルウェアの知識を深めたいと思います。

環境については私自身理解が不十分な点もありますがご了承ください。

構成

構成は以下の通りです。

Windowsに仮想マシンを導入します。仮想マシン内のOSはubuntuです。

ubuntuの中でコンテナを使ってコンテナ上でアプリを動かす環境を作れるようにします。

なお、コンテナを使うことでherokuへの展開も検討しています。

マシン性能

  • OS:Windows 10 pro
  • CPU:Corei7
  • メモリ:24G

手順

構築は以下の手順で行います。




VirtualBox

VirtualBoxをダウンロードしてインストールします。ダウンロード先は以下のurlから行います。

https://www.virtualbox.org/

ダウンロードが完了したら、ファイルをクリックしてインストールを行います。

インストールはウィザードに従って行います。詳細は省略します。

VMwareやWSLも試した結果VirtualBoxが安定しました。

Vagrant

Vagrantをダウンロードしてインストールします。ダウンロード先は以下のurlから行います。

https://www.vagrantup.com/

ダウンロードが完了したら、ファイルをクリックしてインストールを行います。

インストールはウィザードに従って行います。詳細は省略します。

Ubuntu

VirtualboxにUbuntuを設定します。ただし、今回はVagrantのBoxを使用します。

インストール先のフォルダを作成する。

  
D:
 ┗ Vagrant
      ┣  data
      ┗  ubuntu
  

フォルダを作成後、コマンドプロンプトからubuntuに移動します。

  
cd d:\Vagrant\ubuntu\
  

boxからubuntuを設定します。

boxは以下のurlから行います。

https://app.vagrantup.com/boxes/search

今回は、ubuntu/xenial64を使います。

  
vagrant init ubuntu/xenial64

vagrant up
  

起動後一度シャットダウンします。

  
vagrant halt
  

vagrantファイルを更新します。以下を修正します。

  
# -*- mode: ruby -*-
# vi: set ft=ruby :

# All Vagrant configuration is done below. The "2" in Vagrant.configure
# configures the configuration version (we support older styles for
# backwards compatibility). Please don't change it unless you know what
# you're doing.
Vagrant.configure("2") do |config|
  # The most common configuration options are documented and commented below.
  # For a complete reference, please see the online documentation at
  # https://docs.vagrantup.com.

  # Every Vagrant development environment requires a box. You can search for
  # boxes at https://vagrantcloud.com/search.
  config.vm.box = "ubuntu/xenial64"

  # Disable automatic box update checking. If you disable this, then
  # boxes will only be checked for updates when the user runs
  # `vagrant box outdated`. This is not recommended.
  # config.vm.box_check_update = false

  # Provider-specific configuration so you can fine-tune various
  # backing providers for Vagrant. These expose provider-specific options.
  # Example for VirtualBox:
  #
  config.vm.provider "virtualbox" do |vb|
  vb.customize ["modifyvm", :id, "--cableconnected1", "on"]
  #   # Display the VirtualBox GUI when booting the machine
  #   vb.gui = true
  #
  #   # Customize the amount of memory on the VM:
  #   vb.memory = "1024"
  end
  
  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine. In the example below,
  # accessing "localhost:8080" will access port 80 on the guest machine.
  # NOTE: This will enable public access to the opened port
  #config.vm.network "forwarded_port", guest: 80, host: 8080

  # Create a forwarded port mapping which allows access to a specific port
  # within the machine from a port on the host machine and only allow access
  # via 127.0.0.1 to disable public access
  #config.vm.network "forwarded_port", guest: 80, host: 8080, host_ip: "127.0.0.1"

  # Create a private network, which allows host-only access to the machine
  # using a specific IP.
  config.vm.network "private_network", ip: "192.168.33.10"

  # Create a public network, which generally matched to bridged network.
  # Bridged networks make the machine appear as another physical device on
  # your network.
  # config.vm.network "public_network"

  # Share an additional folder to the guest VM. The first argument is
  # the path on the host to the actual folder. The second argument is
  # the path on the guest to mount the folder. And the optional third
  # argument is a set of non-required options.
  config.vm.synced_folder "../data", "/vagrant_data"


  #
  # View the documentation for the provider you are using for more
  # information on available options.

  # Enable provisioning with a shell script. Additional provisioners such as
  # Ansible, Chef, Docker, Puppet and Salt are also available. Please see the
  # documentation for more information about their specific syntax and use.
  # config.vm.provision "shell", inline: <<-SHELL
  #   apt-get update
  #   apt-get install -y apache2
  # SHELL
end
  

ubuntuのアクセスはsshで行います。

sshへのアクセスは、Tera Termを使います。

Tera Termのインストールは以下から行います。

https://forest.watch.impress.co.jp/library/software/utf8teraterm/

インストール後はvagrantを起動します。

  
vagrant up
  

起動後はTera Termからアクセスします。

Docker

Dockerをインストールします。

  
sudo apt-get update

sudo apt-get install apt-transport-https ca-certificates curl software-properties-common

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

sudo apt-key fingerprint 0EBFCD88

sudo apt-get update

sudo apt-get install docker-ce
  

まとめ

今回はwindowsの開発環境構築として、VirtualboxからVagrantを使ってUbuntuをインストールし、そのUbuntuにDockerをインストールするまでのの手順について記載しました。

今後はHerokuへの資産配置等を行います。

コメント

0 件のコメント:

コメントを投稿

コメントをお待ちしています。