Ionic docker image for development, build and continous integration (and certainly useful for all Cordova projects in general as well)
Why
Installing Java and Android SDK is a pain
Keeping your Node modules in sync and up-to-date is a pain
Ensuring all project developers have exactly the same Java version, Android SDK, and node modules is a Sisyphos like task, not to mention your CI environment.
Using a standardized Docker image and a versionednDocker-Compose file for your project ensures an identical environment for all developers, testers, build bots etc.
Features
Based on Ubuntu 16.04
Minimal assumptions/restrictions regarding your development environment and project structure
Build the docker image (grab a coffee, this might take a while when you run it the first time)
docker-compose build
This will only work, if you have docker already installed on your machine. If not, please look at the Usage section for more instructions.
Start the development server
docker-compose up
Congratulations! Look at the default Ionic project at localhost:8100 that is served out of your Docker container.
If you want to know, how to get your own Ionic project served and built out of the Docker container, follow the instructions below.
Usage
Install Docker
Install docker for your platform Linux, Mac or Windows.
Build your image and start your container
You can build your image and start your container directly with docker. Or you can use docker-compose. In general, we recommend to download our compose file and work with docker-compose.
How to develop your local Ionic project in the Docker container
The provided image / container does have an Ionic app setup and installled in the directory /app. This app is only for demo purposes and not intended for development. You you should create / integrate your Ionic project from the host aka your development machine. Therefore, you map your local Ionic project directory to the container via a volume mapping. This will work out of the box if you follow instructions below.
By default, the Docker container has a start script that watches your package.json, which installs on start or on changes.
Usage with docker-compose
To manage the build and run options in your project via cli parameters is a hassle and does not scale very well in larger project teams. Therefore, we recommend to use a compose file, which can be versioned and should be checked into your project repository.
Create your inital docker-compose.yml file
Download it from our repository into your project root
This will generate a Docker image named "my-great-ionic2-project" with the default configuration and a user, who's name is identical to the one on the host.
Feel free to use your image and connect with a bash shell:
This will run the created image with the following features:
Project Directory:
The option -v $PWD:/app:rw will map your hosts current directory to /app in the container. This should allways be our project root directory, where the package.jsons ist provided.
USB Devices:
The option -v /dev/bus/usb:/dev/bus/usb will map your hosts usb ports such that you can build/deploy your project directly to your device.
Attention: this will not work on osx.
Container User Id
The option -u `id -u $USER will run the container with the current user's id. This will avoid permissions issues on the host.
Port Mappings
The defined port mappings ("-p") do map the following ports from the container to the host:
3000: Angular Lite Server
5000: node
8100: ionic
8080: webpack
9876: karma
35729: ionic livereload
Now you have a Docker container, that you can use to develop, build and serve your Ionic (or Cordova) project.
Credits
This project is inspired and builds on various other projects:
Why are you using Ubuntu 16.04 as base Docker image instead of smaller ones like Alpine?*
The goal of this image is to have a standardized development and build environment. Therefore the image should meet a developer's needs in terms of tools, command line usage etc. Since it is not planned to use this image in production or for deployment, minimizing size was not in scope.
Why is this image not available on the Docker hub?
The idea of this image is to have a custom build for your requirements. You might even want to have a separate image per project.
Why are you not running as the root user (like most other ionic images)?
Because this might cause permission issues on your host's mapped application directory. Furthermore, cli calls, tools behavior etc. would differ from a developer's host workflow.
请发表评论