Docker is a containerization technology. It allows one operating system to host different environments, without using virtual machines. It is also cross-platform : containers can be run in Linux, OSX and Windows.

## Why would I use Docker ?

With Docker, you can :

1. upgrade your local Node version without risking to break your app’s dependencies (and avoid using clever hacks to make sure each project uses the correct Node version)
2. be 100% sure that all developers of your team are using the same version of Node, even across different operating systems (prevents NPM dependencies issues)
3. build your app in the exact same, secure, environment

So you have figured it already, Docker lets you work in a controlled environment with the right Node, NPM and dependencies versions.

## Get started

First, make sure Docker is installed, obviously.

docker run --rm -v $(pwd):/src -w /src -p 8080:8080 node:6 bash -c "npm install && npm run dev"  Stop the container with Ctrl+C ### Build for production docker run --rm -v$(pwd):/src -w /src node:6 bash -c "npm install && npm run build"


### Command breakout

--rm tells Docker to delete the container when it is stopped (otherwise you’ll end up with a new container every time you start or build your app).

node:6 is the name of the image.

-v .:/src mounts the current directory (.) at the root of the container in a folder named /src. This is very similar to a virtual drive (Windows) or a virtual disk (Un*x/OSX).

-w /src sets the container’s working directory (where commands will be executed) at the folder we just created.

-p 8080:8080 opens the port 8080 of the container to your local browser (needed by Webpack dev server)

bash -c "..." starts a new bash instance inside the container, useful for such complicated bash commands using an && that may be misinterpreted by your system’s shell.

### Tips

These commands are very long to type but you can make a bash alias (a “shortcut”) by placing it in your .bashrc file (Linux) or .bash_profile (OSX).

alias docker-vue-dev='docker run --rm -v $(pwd):/src -w /src -p 8080:8080 node:6 bash -c "npm install && npm run dev"' alias docker-vue-build='docker run --rm -v$(pwd):/src -w /src node:6 bash -c "npm install && npm run build"'


Make sure to delete the node_modules folder if you have run npm install prior to using docker.

You can change the container’s Node version by replacing node:6 with node:7 or node:latest. Full list of image tags available here.

You can specify environment variables by changing the command to npm install && ENV=staging npm run build

Using Yarn won’t speed up the process that much, as it is faster mostly when NPM modules are cached.

On first run, Docker will throw an error such as Unable to find image 'node:6' locally and will start pulling the image. This is fine, and once an image is pulled it remains on your disk. You can list available images by typing docker images in the terminal.

## Notes

We just scratched the surface of the Docker world. There is a lot more to it.

There is no point in running a Vue.js app in a container as it is meant to be run in a web browser, except during development where Node is used as a web server, or during build where Vue.js tools prepare the final JS code.

Docker concepts are your gateway to implement continuous delivery, integration or just automated builds… Go further and implement Continuous Integration of your Vue.js app with Gitlab.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.15374216437339783, "perplexity": 6262.258827032225}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2018-13/segments/1521257645943.23/warc/CC-MAIN-20180318184945-20180318204945-00394.warc.gz"}