takaya030の備忘録

PHP、Laravel、Docker などの話がメインです

Docker コンテナの中で NetBeans を起動する

ubuntu desktop のイメージを使って NetBeans を起動し、VNC 接続を検証したときの手順メモ

Docker 環境

Windows10 Home Edition
VirtualBox 5.1.6
docker 1.10.3
docker-machine 0.6.0

各種設定ファイル

Dockerfile

FROM dorowu/ubuntu-desktop-lxde-vnc 
LABEL maintainer "takaya030"

RUN sed 's/main$/main universe/' -i /etc/apt/sources.list && \
    apt-get update && apt-get install -y software-properties-common && \
    add-apt-repository ppa:webupd8team/java -y && \
    apt-get update && \
    echo oracle-java8-installer shared/accepted-oracle-license-v1-1 select true | /usr/bin/debconf-set-selections && \
    apt-get install -y oracle-java8-installer && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/* && \
    rm -rf /tmp/*

ADD state.xml /tmp/state.xml

RUN wget http://download.netbeans.org/netbeans/8.2/final/bundles/netbeans-8.2-php-linux-x64.sh -O /tmp/netbeans.sh -q && \
    chmod +x /tmp/netbeans.sh && \
    echo 'Installing netbeans' && \
    /tmp/netbeans.sh --silent --state /tmp/state.xml && \
    rm -rf /tmp/*

ADD run /usr/local/bin/netbeans

state.xml

<?xml version="1.0" encoding="UTF-8"?><!--
  DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
  Copyright 1997-2010 Oracle and/or its affiliates. All rights reserved.
  Oracle and Java are registered trademarks of Oracle and/or its affiliates.
  Other names may be trademarks of their respective owners.
  The contents of this file are subject to the terms of either the GNU General Public
  License Version 2 only ("GPL") or the Common Development and Distribution
  License("CDDL") (collectively, the "License"). You may not use this file except in
  compliance with the License. You can obtain a copy of the License at
  http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
  License for the specific language governing permissions and limitations under the
  License.  When distributing the software, include this License Header Notice in
  each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP.  Oracle
  designates this particular file as subject to the "Classpath" exception as provided
  by Oracle in the GPL Version 2 section of the License file that accompanied this code.
  If applicable, add the following below the License Header, with the fields enclosed
  by brackets [] replaced by your own identifying information:
  "Portions Copyrighted [year] [name of copyright owner]"
  
  Contributor(s):
  
  The Original Software is NetBeans. The Initial Developer of the Original Software
  is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
  Rights Reserved.
  
  If you wish your version of this file to be governed by only the CDDL or only the
  GPL Version 2, indicate your decision by adding "[Contributor] elects to include
  this software in this distribution under the [CDDL or GPL Version 2] license." If
  you do not indicate a single choice of license, a recipient has the option to
  distribute your version of this file under either the CDDL, the GPL Version 2 or
  to extend the choice of license to its licensees as provided above. However, if you
  add GPL Version 2 code and therefore, elected the GPL Version 2 license, then the
  option applies only if the new code is made subject to such option by the copyright
  holder.
--><state xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="state-file.xsd">
<components>
        <product platform="windows linux solaris-sparc solaris-x86 macosx-ppc macosx-x86" status="to-be-installed" uid="nb-base" version="8.2.0.0.201609300101">
            <properties>
                <property name="installation.location.windows">$N{install}/NetBeans 8.2</property>
                <property name="minimum.jdk.version">1.8.0</property>
                <property name="jdk.location">/usr/lib/jvm/java-8-oracle</property>
                <property name="installation.timestamp">1485833188374</property>
                <property name="start.menu.shortcut.location">current.user</property>
                <property name="installation.location.macosx">$N{install}/NetBeans/NetBeans 8.2.app</property>
                <property name="installation.location">/usr/local/netbeans-8.2</property>
                <property name="desktop.shortcut.location">current.user</property>
                <property name="netbeans.summary.message.text">101 updates successfully installed.

</property>
            </properties>
        </product>
        <product platform="windows linux solaris-sparc solaris-x86 macosx-ppc macosx-x86" status="to-be-installed" uid="nb-extide" version="8.2.0.0.201609300101">
            <properties>
                <property name="show-in-wizard">false</property>
                <property name="installation.location">/usr/local/netbeans-8.2</property>
            </properties>
        </product>
        <product platform="windows linux solaris-sparc solaris-x86 macosx-ppc macosx-x86" status="to-be-installed" uid="nb-webcommon" version="8.2.0.0.201609300101">
            <properties>
                <property name="installation.location">/usr/local/netbeans-8.2</property>
            </properties>
        </product>
        <product platform="windows linux solaris-sparc solaris-x86 macosx-ppc macosx-x86" status="to-be-installed" uid="nb-php" version="8.2.0.0.201609300101">
            <properties>
                <property name="installation.location">/usr/local/netbeans-8.2</property>
            </properties>
        </product>
        <product platform="windows linux solaris-sparc solaris-x86 macosx-ppc macosx-x86" status="to-be-installed" uid="nb-cnd" version="8.2.0.0.201609300101">
            <properties>
                <property name="installation.location">/usr/local/netbeans-8.2</property>
            </properties>
        </product>
        <product platform="windows linux solaris-sparc solaris-x86 macosx-ppc macosx-x86" status="to-be-installed" uid="nb-ergonomics" version="8.2.0.0.201609300101">
            <properties>
                <property name="installation.location">/usr/local/netbeans-8.2</property>
            </properties>
        </product>
    </components>
</state>

run

#!/bin/bash

# Make sure the user data directory is owned by the ubuntu user
if [ -d /home/ubuntu/.netbeans ]; then
  sudo chown ubuntu:ubuntu /home/ubuntu/.netbeans
fi
exec /usr/local/netbeans-8.2/bin/netbeans

イメージのビルド

$ docker build -t takaya030/netbeans

イメージの確認

$ docker images
REPOSITORY                       TAG                 IMAGE ID            CREATED             SIZE
takaya030/netbeans               latest              a74eced20d24        13 minutes ago      2.09GB
dorowu/ubuntu-desktop-lxde-vnc   latest              54ee7716013e        7 weeks ago         1.23GB

動作確認

$ docker run --rm -it -p 80:80 takaya030/netbeans

WEBブラウザで "http://192.168.99.100" にアクセスすると ubuntu desktop の画面が表示される
左下のメニューボタンから LXTerminal を起動する
f:id:takaya030:20170423125256p:plain

ターミナルで "/usr/local/bin/netbeans &" と入力する
f:id:takaya030:20170423125318p:plain

NetBeans が起動できれば成功
f:id:takaya030:20170423125339p:plain