docker中使用vue-cli
-
image選擇:hub.docker.com中自行搜索,這里用到的是:
docker pull ebiven/vue-cli
-
該作者的介紹比較簡單,但是在使用中踩了一些坑才成功,作者的使用說明:
In your .bashrc, .zshrc, or similar file include aliases for the following commands:
alias vue='docker run -it --rm -v "$PWD":"$PWD" -w "$PWD" -u "$(id -u)" ebiven/vue-cli vue'
根據系統在不同文件修改,如我的ubuntu在.bashrc中添加 alias vue=...
,這里需要注意,最好將npm node的別名一起設置,且在npm設置的時候添加端口映射,最終代碼如:
.bashrc 添加后執行 source ~/.bashrc使其生效
alias vue='docker run -it --rm -p 9999:8080 -v "$PWD":"$PWD" -w "$PWD" -u "$(id -u)" ebiven/vue-cli vue'
alias npm='docker run -it --rm -p 9998:8080 -v "$PWD":"$PWD" -w "$PWD" -u "$(id -u)" ebiven/vue-cli npm'
alias node='docker run -it --rm -p 9997:8080 -v "$PWD":"$PWD" -w "$PWD" -u "$(id -u)" ebiven/vue-cli node'
大功告成
$ vue create vue-project
$ cd vue-project
$ npm run serve
注意事項
- 注意宿主機和容器端口的映射:執行
npm run serve
時,才能從瀏覽器 IP:端口 的方式訪問 如:http://localhost:9998
- 在root賬戶下執行。