Vagrant configuration to setup a http://jhipster.github.io/ projet using ubuntu/trusty64 box.
Based on instructions at: http://jhipster.github.io/installation.html
jhipster-standalone/
contains a vagrant conf with jhispter directly usable in ubuntu
jhipster-docker/
contains a vagrant conf with https://github.com/jhipster/jhipster-docker embedded in it
Copy the Vagrantfile somewhere
vagrant up
// ... long setup...
vagrant ssh
In the vagrant box
vagrant@vagrant-ubuntu-trusty-64:/vagrant$ yo jhipster
// follow instrucutions
exit
On your host machine: git add, commit, push
git clone (repo with the Vagrantfile in it and the jhipster folders)
vagrant up
Basically it just scripting that does this:
JHipster has a specific jhipster-docker project, which provides a Docker container.
This project makes a Docker "Trusted build" that is available on:
https://registry.hub.docker.com/u/jdubois/jhipster-docker/
This image will allow you to run JHipster inside Docker.
Linux supports out-of-box. You just need to follow the tutorial on the Docker website.
Docker uses Linux-specific kernel features so it doesn't run direcly on MAC or Windows. Different solutions are available for MAC and Windows users.
- Boot2docker - This is an official docker application to use speed up Docker on non-linux platform.
- Virtualbox - A Virtual Machine with Docker must be installed
- Vagrant - Use Virtualbox as provider and docker as Plugin
-
Install Boot2docker
-
Initialize boot2docker - a boot2docker ISO image (tiny VM) will be downloaded and installed in the ~/.boot2docker folder.
boot2docker init
-
Add a portmap to the VM to expose the port to your host
VBoxManage modifyvm "boot2docker-vm" --natpf1 "containerssh,tcp,,4022,,4022"
VBoxManage modifyvm "boot2docker-vm" --natpf1 "containertomcat,tcp,,8080,,8080"
VBoxManage modifyvm "boot2docker-vm" --natpf1 "containergruntserver,tcp,,9000,,9000"
VBoxManage modifyvm "boot2docker-vm" --natpf1 "containergruntreload,tcp,,35729,,35729"
-
Start boot2docker
boot2docker up
Pull the JHipster Docker image:
sudo docker pull jdubois/jhipster-docker
Create a "jhipster" folder in your home directory:
mkdir ~/jhipster
Run The docker image, with the following options:
- The Docker "/jhipster" folder is shared to the local "~/jhipster" folder
- Forward all ports exposed by docker (8080 for Tomcat, 9000 for the "grunt serve" task, 35729 for the live reload with grunt-contrib-watch and 22 for SSHD). In the following example we forward the container 22 port to the host 4022 port, to prevent some port conflicts:
sudo docker run -v ~/jhipster:/jhipster -p 8080:8080 -p 9000:9000 -p 35729:35729 -p 4022:22 -t jdubois/jhipster-docker
Pull the JHipster Docker image:
docker pull jdubois/jhipster-docker
Create a "jhipster" folder in your home directory:
mkdir ~/jhipster
Run The docker image, with the following options:
- Forward all ports exposed by docker (8080 for Tomcat, 9000 for the "grunt serve" task, 35729 for the live reload with grunt-contrib-watch and 22 for SSHD). In the following example we forward the container 22 port to the host 4022 port, to prevent some port conflicts
docker run -d -p 8080:8080 -p 9000:9000 -p 35729:35729 -p 4022:22 -t jdubois/jhipster-docker
Make a volume container
The Docker -v option should be used to share the Docker "/jhipster" folder to the local "~/jhipster" folder. However, this option doesn't work on MAC (issue 4023 on docker project). The workaround is to use the svendowideit/samba project. More information can be found on the https://github.com/boot2docker/boot2docker#folder-sharing section on the boot2docker website.
-
Retrieve the name of the container
Here is the resultat of the command `docker ps`. Get the name at the column NAMES.
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
418448ff3371 jdubois/jhipster-docker:latest "/bin/sh -c '/usr/sb 59 minutes ago Up 59 minutes 0.0.0.0:4022->22/tcp, 0.0.0.0:8080->8080/tcp, 0.0.0.0:9000->9000/tcp, 0.0.0.0:35729->35729/tcp naughty_bartik -
Add the samba support.
docker run --rm -v /usr/local/bin/docker:/docker -v /var/run/docker.sock:/docker.sock svendowideit/samba naughty_bartik
-
Folder sharing
goto Go|Connect to Server in Finder
enter 'cifs://192.168.59.103
hit the 'Connect' button
select the volumes you want to mount
choose the 'Guest' radiobox and connect
-
Once mounted, will appear as /Volumes/jhipster. Create a symlink to make the volume accessible in the local "~/jhipster" folder.
ln -s /Volumes/jhipster ~/jhipster
You can now connect to your docker container with SSH. You can connect as "root/jhipster" or as "jhipster/jhipster", and we recommand you use the "jhipster" user as some of the tool used are not meant to be run by the root user.
Start by adding your SSH public key to the Docker container:
cat ~/.ssh/id_rsa.pub | ssh -p 4022 jhipster@localhost 'mkdir ~/.ssh && cat >> ~/.ssh/authorized_keys'
You can now connect to the Docker container:
ssh -p 4022 jhipster@localhost
You can then go to the /jhipster directory in your container, and start building your app inside Docker:
cd /jhipster
yo jhipster
If the following exception occurs, you need to change the owner of the /jhipster directory. See next step.
...
? (13/13) Would you like to use the Compass CSS Authoring Framework?: No
/usr/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/node_modules/mkdirp/index.js:89
throw err0;
^
Error: EACCES, permission denied '/jhipster/src'
at Object.fs.mkdirSync (fs.js:653:18)
at sync (/usr/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/node_modules/mkdirp/index.js:70:13)
at sync (/usr/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/node_modules/mkdirp/index.js:76:24)
at Function.sync (/usr/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/node_modules/mkdirp/index.js:76:24)
at JhipsterGenerator.app (/usr/lib/node_modules/generator-jhipster/app/index.js:419:10)
at /usr/lib/node_modules/generator-jhipster/node_modules/yeoman-generator/lib/base.js:387:14
at processImmediate [as _immediateCallback] (timers.js:345:15)
You need to fix the jhipster folder to give the "jhipster" user ownership of the directory:
ssh -p 4022 jhipster@localhost
sudo chown jhipster /jhipster
Once your application is created, you can run all the normal grunt/bower/maven commands, for example:
mvn spring-boot:run
Congratulations! You've launched your JHipster app inside Docker!
On your host machine, you should be able to :
- Access the running application at http://localhost:8080
- Get all the generated files inside your shared folder
As the generated files are in your shared folder, they will not be deleted if you stop your Docker container. However, if you don't want Docker to keep downloading all the Maven and NPM dependencies every time you start the container, you should commit its state.