ref:
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-docker-on-ubuntu-16-04
https://philipzheng.gitbooks.io/docker_practice/content/install/ubuntu.html
Docker官方英文
安裝
需求:
1.64-bit
2.kernel > 3.10 ($ uname -r)
更新套件資源$ sudo apt-get update
確保APT可以用https method, 和CA certificates (這兩個通常都有了)$ sudo apt-get install apt-transport-https ca-certificates
新增GPG key取得最新Docker官方的版本$ sudo apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
Add the Docker repository to APT sources:
打開/etc/apt/sources.list.d/docker.list
加入根據作業系統版本的repo
Ubuntu Xenial 16.04 (LTS) : deb https://apt.dockerproject.org/repo ubuntu-xenial main
簡化之:echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
把剛剛加的更新進去$ sudo apt-get update
(Optional)以前裝過就要下這個 : Purge the old repo if it exists.$ sudo apt-get purge lxc-docker
確認現在是不是指向新的Docker版本$ apt-cache policy docker-engine
應該會看到類似下列訊息
(Optional)官方表示Ubuntu16.04建議安裝這個:linux-image-extra-*
(kernel packages,
allows you use the aufs storage driver)$ sudo apt-get install linux-image-extra-$(uname -r) linux-image-extra-virtual
終於可以裝囉$ sudo apt-get install docker-engine
查看狀態$ sudo systemctl status docker
(Optional)不sudo用docker
將使用者新增到docker群組sudo usermod -aG docker $(whoami)
sudo usermod -aG docker [the username]
再重開terminal
Hello World!
docker run hello-world
Usage
找尋你想要的套件docker search ubuntu
棒docker search -s 1 redis | more
(-s是stars)
下載下來docker pull ubuntu
==docker pull registry.hub.docker.com/ubuntu:16.04
看載了什麼docker images
建立一個containerdocker run ubuntu
進去互動docker run -it ubuntu
-i, –interactive, Keep STDIN open even if not attached
-t, –tty, Allocate a pseudo-TTY
完整指令讓他執行bashsudo docker run -t -i ubuntu:16.04 /bin/bash
以Daemonized狀態執行 : 加 -d
正在運行的containerdocker ps
看所有的containerdocker ps -a
啟動containerdocker start container-id
進入containerdocker exec -it container-id /bin/bash
docker attach container-id
停止containerdocker stop container-id
刪除containerdocker rm container-id
刪除imagedocker rmi image-id
Commit(冒號後面加taag, tag不一定要加)docker commit -m "What did you do to the image" -a "Author Name" container-id repository/new_image_name:tag
ex:docker commit -m "added node.js" -a "Sunday Ogwu-Chinuwa" d9b100f2f636 finid/ubuntu-nodejs
製作一個ubuntu-nodejs image步驟:docker run -it ubuntu
apt-get update
apt-get install -y nodejs
exit
docker commit -m "added node.js" -a "Name" 23678e0625bd DockerHub的Username/ubuntu-nodejs
上傳到Docker Hubdocker login -u DockerHub的Username
docker push DockerHub的Username/ubuntu-nodejs
利用 Dockerfile 建立映像檔
vim Dockerfile
docker build -t="lovenery/sinatra:v2" .
-t可以指定新的tag, 第二個點 . 是Dockerfile所在目錄(當前目錄)
可以利用docker tag 52680c5e789d lovenery/sinatra
任意修改tag
Nginx Example
echo "<h1>Hello!</h1>" | tee index.html
vim Dockerfile
docker build -t webserver-image:v1 .
docker run -d -p 8080:80 webserver-image:v1
http://localhost:8080
Nginx Example 2
|
|
docker build -t my-nginx-image:latest .
docker run -d -p 8080:80 my-nginx-image:latest
安裝 Docekr Composer
https://docs.docker.com/compose/install/
https://github.com/docker/compose/releases
sudo -i
or sudo -s
|
|
$ docker-compose --version
=>docker-compose version: 1.8.0