2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

VboxとSambaを用いたwindows10 HomeでのDocker環境の構築

Last updated at Posted at 2020-05-30

概要

 先日WSL2が正式リリースとなりwindows homeでもDockerが使えるようになりましたが、個人的にLinux版のDockerのほうが好みだったので、windowsでLinux版Dockerを使えないか考えたところネットワークドライブを使えば可能なのでは??と思ったので作ってみました。

準備

  • Vbox(Hyper-vでも可)
  • CentOS7のISO(8やubuntuでも可)

手順

仮想マシンの作成

  1. VMにNATアダプター、ホストオンリーアダプターを追加する。
  2. VboxでCentOS7のVMを立ち上げる。
  3. yum -y updateを実行し最新版にする。

パッケージのインストール

yum remove docker docker-client docker-client-latest docker-common docker-latest docker-latest-logrotate docker-logrotate docker-engine
yum install -y yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum -y install samba samba-common docker-ce docker-ce-cli
curl -L https://github.com/docker/compose/releases/download/1.21.2/docker-compose-$(uname -s)-$(uname -m) -o /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

Sambaの構築

サービスの起動、Firewallの設定、SeLinuxの無効化

systemctl start smb nmb
systemctl enable smb nmb
firewall-cmd --add-service=samba --permanent
firewall-cmd --reload
vi /etc/selinux/config
    SELINUX=enforcing    //enforcingをdisabledに変更
vi /etc/samba/smb.conf   //下記のように変更
mkdir /develop           //このディレクトリがネットワークドライブとして割り当てられる
testparm                 //smb.confにエラーがないか確認

    Load smb config files from /etc/samba/smb.conf
    Loaded services file OK.
    Server role: ROLE_STANDALONE

    Press enter to see a dump of your service definitions

    # Global parameters
    [global]
        disable spoolss = Yes
        dos charset = CP932
        load printers = No
        netbios name = FS
        security = USER
        wins support = Yes
        workgroup = CRAYON
        idmap config * : backend = tdb


    [homes]
        comment = Home Directories
        inherit acls = Yes
        read only = No
        valid users = %S %D%w%S


    [Share]
        comment = Share Folder for All Users
        path = /develop
        read only = No
chmod -R 0777 /develop/
chown -R nobody:nobody /develop/

/etc/samba/smb.confの内容

[global]
#       workgroup = SAMBA
        workgroup = <windos work group>
        security = user

        netbios name = fs

        unix charset = UTF-8
        dos charset = CP932
        wins support = yes

        passdb backend = tdbsam

#       printing = cups
#       printcap name = cups
#       load printers = yes
        load printers = no
        disable spoolss = yes
#       cups options = raw

[homes]
        comment = Home Directories
        valid users = %S, %D%w%S
        browseable = yes
        writable = yes
        read only = no
        inherit acls = Yes

[Share]
        comment = Share Folder for All Users
        path = /develop
        browsable = yes
        writable = yes
        read only = no

# [printers]
#       comment = All Printers
#       path = /var/tmp
#       printable = Yes
#       create mask = 0600
#       browseable = No

# [print$]
#       comment = Printer Drivers
#       path = /var/lib/samba/drivers
#       write list = @printadmin root
#       force group = @printadmin
#       create mask = 0664
#       directory mask = 0775

Sambaアクセス用ユーザー追加

 今回のファイルサーバーでは、ゲストアカウントはアクセスできないため、アクセス用にユーザーの作成が必要になります。ユーザーはLinux側で作成した後に、Sambaに用意されている"pdbedit"コマンドでファイルサーバー用に設定を行います。ここでは”rem-test01”というユーザーを作成してみます。

useradd rem-test01
passwd rem-test01
ユーザー rem-test01 のパスワードを変更。
新しいパスワード:     任意のパスワード
新しいパスワードを再入力してください:     同じパスワードを入力
passwd: すべての認証トークンが正しく更新

pdbedit -a -u rem-test01 -f "windows user name"
new password:     passwdコマンドで設定したものと同じパスワードを入力
retype new password:     確認用にパスワードを再入力

pdbedit -L
rem-test01:1004:<windows user name>

systemctl restart smb nmb

確認・接続

CMDよりping fsを実行して到達するかを確認します。pingの応答が確認できたら、次にコンピューター名を指定してSambaサーバーへ接続できることを確認します。windowsキー+Rでファイル名を指定して実行できるのでそこで表示されたダイアログの名前に”\\fs”と入力してOKをクリックします。「ネットワーク資格情報の入力」ダイアログが開きます。ここで先ほど作ったlinux userの情報を入力します。入力した情報が正しい場合、エクスプローラーに設定した共有フォルダが表示されます。
このShareが/developの下になってるはずです。\Shareでフォルダーを作成して/developに配置されていれば構築完了です。/developにwindowsからcompose fileを作成してsshでBuildすればDocker環境として利用することができるともいます。

注意点

windowsの設定でVboxがバックグラウンドで稼働できない設定になっている場合スリーブを実行した際に仮想マシンが停止してしまう場合があるようです。スリーブ機能を多用する方は気を付けてください

2
0
2

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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?