2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

dockerにUbuntuをいれてNetBeansをX転送して使えるようになった。

Last updated at Posted at 2024-05-19

dockerにUbuntuをいれてNetBeansをX転送して使えるようになった。

Xmingをインストール

Xming-fontsをインストール

眼玉を出してみるDocker

dockerfile
FROM centos:centos7
RUN yum install -y xeyes \
 && useradd -m testuser \
 && useradd -m testuser2
USER testuser
ENV DISPLAY=host.docker.internal:0.0
ENTRYPOINT ["bash"]

build

docker build . -t xeyes:1

このコマンドで目玉ウインドウがでればOK

docker run --rm -it -t xeyes:1 -c xeyes

DISPLAYのところはdockerfileに以下を入れておいてもいいのか?
「host.docker.internal」はホストOSのIPアドレスを表すらしい(←よくわかってない)
host.docker.internalのところに直接IPアドレスを書いてもよい

ENV DISPLAY=host.docker.internal:0.0

画面が出ない場合)

右下Xmingのアイコン右クリック「View Log」にエラーメッセージ出てる
以下にホストのIPアドレスを追記しないとだめかも
C:\Program Files (x86)\Xming\X0.hosts

目玉がでたなら次へ

ubuntuにJava8+NetBeans17を入れてGUIで使う

dockerfile

dockerfile
# Ubuntuをベースイメージとして使用
FROM ubuntu:24.04

# 必要なパッケージをインストール
RUN apt-get update && apt-get install -y \
    software-properties-common \
    wget \
    unzip

# Java8のインストール
RUN add-apt-repository ppa:openjdk-r/ppa \
    && apt-get update -q \
    && apt install -y openjdk-8-jdk
    #&& apt install -y openjdk-11-jdk

# NetBeans17のインストール
RUN wget https://archive.apache.org/dist/netbeans/netbeans-installers/17/apache-netbeans_17-1_all.deb \
    && apt install -y ./apache-netbeans_17-1_all.deb \
    && rm ./apache-netbeans_17-1_all.deb

# 日本語化パッケージをインストールするして日本語環境設定にする
RUN apt install -y language-pack-ja-base language-pack-ja ibus-mozc \
    && echo 'export LANG=ja_JP.utf8' >> ~/.bashrc \
    && echo 'export LANGUAGE="ja_JP:ja"' >> ~/.bashrc

# NetBeansを日本語化(ツーループラグインーインストールを開いて以下nbmファイルをインストールする)
RUN wget https://github.com/junichi11/netbeans-translations-ja/releases/download/v0.0.4/org-apache-netbeans-localise-ja-0.0.4.nbm \
    && chmod +x org-apache-netbeans-localise-ja-0.0.4.nbm
RUN mv org-apache-netbeans-localise-ja-0.0.4.nbm /root/

# 日本語フォントをインストール(Javaソフトの日本語が豆腐になるのを防ぐ)
RUN apt install -y fonts-takao-gothic


# ポート8080を公開(ここいらないか)
EXPOSE 8080

# コンテナ起動時にNetBeansを起動
CMD ["/bin/bash"]


# netbeans GUIを起動
# netbeans &

docker-compose.yml

docker-compose.yml
version: '3'
services:
  netbeans:
    build:
      context: .
      #dockerfile: Dockerfile
    environment:
      - DISPLAY=host.docker.internal:0.0
      - USER_ID=${USER_ID:-1000}
      - GROUP_ID=${GROUP_ID:-1000}
    group_add:
      - audio
      - video
    ports:
      - "8080:8080"
    volumes:
      - ./.cache:/home/developer/.cache
      - ./.netbeans:/home/developer/.netbeans
      - ./data:/home/developer/data
      - ./workspace:/home/developer/workspace
      
    tty: true
    stdin_open: true

#    command: netbeans &

docker起動

docker-compose up -d

dockerに入る

docker-compose exec -it netbeans bash

NetBeans起動

netneans &

docker-composeのサービス名「netbeans」とGUIアプリとしての「netbeans」がどっちがどっちかまぎらわしい
直接起動すると、日本語にならないので、bashで入ってから起動する(なぜかな?)

日本語化(初回のみ)

NetBeansが起動したら
「ツール」ー「プラグイン」を開く
「ダウンロード済」ー「プラグインの追加」
/root/org-apache-netbeans-localise-ja-0.0.4.nbm
を選択
NetBeansを再起動すると日本語になっているはず

image.png

はまったこと

NetBeansをインストールしたままだと英語なので、日本語化パッケージをインストールするが、なぜか□になってしまう。

Java側が日本語フォントに対応していないようで、フォントをインストールした
dockerfileのこの部分RUN apt install -y fonts-takao-gothic

はまったこと2

Windowsの通知設定のせいでDokerがビルド出来ない
参考にさせていただきました
https://qiita.com/ucan-lab/items/421ead96c830f7eb4b00

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?