├── Dockerfile ├── README.md └── init.sh /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM node:8 2 | 3 | LABEL maintainer="Stephen Afam-Osemene " 4 | 5 | # ------------------------------------------ 6 | # install the adonis CLI 7 | # ------------------------------------------ 8 | RUN npm i -g @adonisjs/cli 9 | 10 | # ------------------------------------------ 11 | # change the work directory 12 | # ------------------------------------------ 13 | WORKDIR /var/www 14 | 15 | # ------------------------------------------ 16 | # copy our initilization file and set permissions 17 | # ------------------------------------------ 18 | COPY init.sh /init.sh 19 | RUN chmod 755 /init.sh 20 | 21 | CMD ["/init.sh"] -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AdonisJs Docker image 2 | 3 | This is a docker image for AdonisJs 4 | 5 | ## How to use 6 | 7 | pull the docker image 8 | 9 | docker pull stephenafamo/adonisjs:1.0.0 10 | 11 | Run the docker image and create your container 12 | 13 | docker run --name adonisjs adonisjs 14 | 15 | 16 | ### Volumes and working directory 17 | 18 | The working directory inside the container is `/var/www` so to keep your application data, you can mount a directory onto that volume 19 | 20 | docker run --name adonisjs -v /path/to/app:/var/www stephenafamo/adonisjs:1.0.0 21 | 22 | You can change the working directory by passing the `-w` flag, if you do, please make sure to update the mounted volume to preserve data. For example 23 | 24 | docker run --name adonisjs -w /usr/app -v /path/to/app:/usr/app stephenafamo/adonisjs:1.0.0 25 | 26 | ### Custom application type 27 | 28 | If the working directory is empty, the image will create a new adonis application in that directory. 29 | To modify the type of application add flags to the `adonisFlags` environmental variable. 30 | 31 | docker run --name adonisjs -v /path/to/app:/var/www -e "adonisFlags=--slim --yarn" stephenafamo/adonisjs:1.0.0 32 | 33 | To see possible options, visit the [documentation](http://dev.adonisjs.com/docs/4.0/installation#_customizing_new_command) 34 | 35 | ### Server type 36 | 37 | By default the server started is the development server, which will watch for changes to files. However, if the `NODE_ENV` in the `.env` file is set to `production` it will start the production server. **This does not watch for changes to files.** 38 | 39 | ## Viewing your application in your browser 40 | 41 | This image will start the adonis server using the `HOST` and `PORT` specified in your `.env` file. 42 | 43 | #### HOST 44 | Because of the way docker works. If you already have an Adonis application and you want to run it in a docker container, **you'll have to chage the `HOST` in your `.env` file to `0.0.0.0`**. 45 | 46 | If you used this image to create the application, it will do this for you. 47 | 48 | #### PORT 49 | The default port of adonis applications is `3333`. 50 | If the application was created by this imaged, it is changed to `80` 51 | 52 | To be able to visit your application, map a port on your host machine to the application port defined in the `.env` file. 53 | 54 | docker run --name adonisjs -v /path/to/app:/var/www -p 1234:80 stephenafamo/adonisjs:1.0.0 55 | 56 | Then you can visit the application on `http://0.0.0.0:1234` 57 | 58 | ## Self-Promotion 59 | 60 | If you like this project, please star the repository on [GitHub](https://github.com/stephenafamo/adonisjs-docker) You might also consider visiting my [blog](https://stephenafamo.com/blog) and following me on [Twitter](https://twitter.com/stephenafamo) and [Github](https://github.com/stephenafamo). -------------------------------------------------------------------------------- /init.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [[ -z "$(ls -A $PWD 2>/dev/null)" ]]; then 4 | adonis new . $adonisFlags 5 | sed -i -e "s/HOST=.*/HOST=0.0.0.0/g" .env 6 | sed -i -e "s/PORT=.*/PORT=80/g" .env 7 | fi 8 | 9 | if [[ -z "$(ls -A $PWD | grep .env)" ]]; then 10 | echo "no .env file found." 11 | exit 1 12 | fi 13 | 14 | npm install 15 | 16 | source .env 17 | 18 | if [[ "$NODE_ENV" == "production" ]]; then 19 | adonis serve 20 | else 21 | adonis serve --dev 22 | fi 23 | --------------------------------------------------------------------------------