LoginSignup
0
0

LXDCLIでサクッとjavaの環境を用意する

Last updated at Posted at 2023-10-18

目的

Javaでアプリケーションを開発しなさいというお達しが来ました。しかし、僕にはjavaの開発環境がありません。今回はLXDCLIでさくっとjava環境を手に入れましょう。

ファイルの用意

lxdfile

FROM ubuntu/22.04

RUN systemctl restart systemd-resolved
RUN echo "nameserver 8.8.8.8" >> /etc/resolv.conf
RUN dhclient


RUN export DEBIAN_FRONTEND=noninteractive
RUN timedatectl set-timezone Asia/Tokyo && hostnamectl set-hostname ubuntu-java2
RUN apt-get -y update

RUN dpkg --configure -a
RUN echo "\n\n\n" | apt-get -y install openssh-server
RUN apt-get -y install docker docker.io docker-compose nano curl openjdk-17-jdk

RUN echo -e "root:password" | chpasswd
RUN echo -e 'PermitRootLogin  yes' >> /etc/ssh/sshd_config


RUN systemctl enable ssh
RUN systemctl restart ssh
RUN systemctl start ssh


RUN echo "JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")" >  ~/.bashrc
RUN echo "export JAVA_HOME" > ~/.bashrc
RUN echo "PATH=$PATH:$JAVA_HOME/bin" > ~/.bashrc
RUN echo "export PATH" > ~/.bashrc
RUN source ~/.bashrc

RUN mkdir -p ~/tmp/hello-java

構築

$ lxdcli build lxdfile

ログイン

$ lxc shell ubuntu-java

確認

root@ubuntu-java:~# java
Usage: java [options] <mainclass> [args...]
           (to execute a class)
   or  java [options] -jar <jarfile> [args...]
           (to execute a jar file)
   or  java [options] -m <module>[/<mainclass>] [args...]
       java [options] --module <module>[/<mainclass>] [args...]
           (to execute the main class in a module)
   or  java [options] <sourcefile> [args]
           (to execute a single source-file program)

 Arguments following the main class, source file, -jar <jarfile>,
 -m or --module <module>/<mainclass> are passed as the arguments to
 main class.

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