Docker教學
安裝
OSX: https://docs.docker.com/docker-for-mac/install/
windows版本的docker建議可以使用kitemantic整合環境
windows: https://kitematic.com/
https://store.docker.com/search?type=edition&offering=community
windows使用kitemantic後點選右下角的DOCKER CLI
以下為Docker執行Redis與Node.js server並分別expose兩個PORT的範例
1.新增package.json
{
"name": "docker_web_app",
"version": "1.0.0",
"description": "Node.js on Docker",
"author": "First Last <first.last@example.com>",
"main": "server.js",
"scripts": {
"start": "node server.js"
},
"dependencies": {
"express": "^4.13.3"
}
}2.server.js
3.Dockerfile
4.
建立image
(-t 為tag 的意思即為這個image的名字)
5.
執行image
(意思為把Node.js server之8080port開放給外面電腦的49160,與開放Redis的6379給外面電腦的49161)
開啟瀏覽器localhost:49160即可看到
6.連線到Redis
記得先進去container開啟Redis-server
之後會顯示如下
然後用exec的方法進入docker的Process 之cli
啟動Redis
7.之後寫一個Node.js的程式來連Redis
把image搬到其他電腦
把最後面參數名字的image(剛才tag名稱)存成 dockerImage 壓縮檔
然後把此image壓縮檔移到在別台電腦及可讀取
PUSH Image到Docker Hub
1.先到https://hub.docker.com/註冊帳號
2.Create new repository
3.登入
4.查看你要push的image的ID
5.把ID配上你的repository名稱
6.推送
https://ropenscilabs.github.io/r-docker-tutorial/04-Dockerhub.html
減少 Build 後 Image 檔案大小
使用 multistage build
https://docs.docker.com/develop/develop-images/multistage-build/
Last updated
Was this helpful?