docker 直譯為碼頭工人。當它成為一種技術時,做的也是碼頭工人的事。官網(wǎng)是這樣描述它的:“Docker是一個開發(fā)的平臺,用來為開發(fā)者和系統(tǒng)管理員構建、發(fā)布和運行分布式應用。”也就是說,如果把你的應用比喻為貨物,那么碼頭工人(Docker)就會迅速的用集裝箱將它們裝上船??焖佟⒑唵味行?。`
它是用 Go 語言寫的,是程序運行的“容器”(Linux containers),實現(xiàn)了應用級別的隔離(沙箱)。多個容器運行時互補影響,安全而穩(wěn)定。
我喜歡它的原因就是快速部署,安全運行,不污染我的系統(tǒng)。
官方提供一個互動的小教程,讓你很容易的了解 Docker 的基本用法,快去試試吧!
官方直接支持 64 位 Linux 系統(tǒng)安裝 Docker,但如果想在 32 位系統(tǒng)中運行,有人也進行了一些嘗試,比如 32Ubuntu 下,參考點擊打開鏈接。
其他系統(tǒng)的安裝請參考官網(wǎng),下面說說我在 Ubuntu14.04 下的安裝。
1.將鏡像加入到程序源中:
~$ sudo sh -c "echo deb http://mirror.yandex.ru/mirrors/docker/ docker main > /etc/apt/sources.list.d/docker.list"
2.接著 update
$ sudo apt-get update
3.如果報錯就 fix 掉它:
W: GPG error: http://mirror.yandex.ru docker Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D8576A8BA88D21E9\
解決此錯誤:
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys D8576A8BA88D21E9
Executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.RmJ1SUpsXX --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys D8576A8BA88D21E9
gpg: requesting key A88D21E9 from hkp server keyserver.ubuntu.com
gpg: key A88D21E9: public key "Docker Release Tool (releasedocker) <docker@dotcloud.com>" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
4.下載 docker:
$ sudo apt-get install lxc-docker
靜靜的等待它下載完成吧。
另外,這個命令也許會有幫助:
$ curl -sSL https://get.docker.com/ubuntu/ | sudo sh
終端中輸入 docker,打印出 docker 的命令列表:
Commands:
attach Attach to a running container
build Build an image from a Dockerfile
commit Create a new image from a container's changes
cp Copy files/folders from a container's filesystem to the host path
create Create a new container
diff Inspect changes on a container's filesystem
events Get real time events from the server
exec Run a command in a running container
export Stream the contents of a container as a tar archive
history Show the history of an image
images List images
import Create a new filesystem image from the contents of a tarball
info Display system-wide information
inspect Return low-level information on a container
kill Kill a running container
load Load an image from a tar archive
login Register or log in to a Docker registry server
logout Log out from a Docker registry server
logs Fetch the logs of a container
port Lookup the public-facing port that is NAT-ed to PRIVATE_PORT
pause Pause all processes within a container
ps List containers
pull Pull an image or a repository from a Docker registry server
push Push an image or a repository to a Docker registry server
restart Restart a running container
rm Remove one or more containers
rmi Remove one or more images
run Run a command in a new container
save Save an image to a tar archive
search Search for an image on the Docker Hub
start Start a stopped container
stop Stop a running container
tag Tag an image into a repository
top Lookup the running processes of a container
unpause Unpause a paused container
version Show the Docker version information
wait Block until a container stops, then print its exit code
接下來就可以嘗試使用這些命令了,不過在進行下一步之前,我們要先了解幾個概念。
image 鏡像 鏡像就是一個只讀的模板。比如,一個鏡像可以包含一個完整的 Ubuntu 系統(tǒng),并且安裝了 apache。 鏡像可以用來創(chuàng)建 Docker 容器。 其他人制作好鏡像,我們可以拿過來輕松的使用。這就是吸引我的特性。
Docker container 容器 Docker 用容器來運行應用。容器是從鏡像創(chuàng)建出來的實例(好有面向對象的感覺,類和對象),它可以被啟動、開始、停止和刪除。
1.search
搜索倉庫中是否有 wordpress 這個博客鏡像,如下:
$ docker search wordpress
NAME DESCRIPTION STARS OFFICIAL AUTOMATED
wordpress The WordPress rich content management syst... 185 [OK]
2.下載這個鏡像
$ docker pull wordpress
wordpress:latest: The image you are pulling has been verified
3.查看自己的鏡像
$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
linc-wiki latest b5a1e34b01c2 27 hours ago 689.7 MB
ubuntu latest 5ba9dab47459 5 days ago 188.3 MB
wordpress latest ecc04d6d638c 6 days ago 470 MB
4.簡單的運行
運行 wordpress 要進行 mysql 的配置,為了演示 run,將 ubuntu 跑起來吧。
$ docker run -it ubuntu /bin/bash
root@46ff2a695ce1:/# echo "I am linc"
I am linc
至此,體驗結束。后續(xù)會有更加精彩的實踐等著我們,Docker,我們來了!
參考:
https://docs.docker.com/installation/ubuntulinux/
https://bitnami.com/stack/mediawiki
https://docs.docker.com/userguide/
https://dockerpool.com/static/books/docker_practice
http://zhumeng8337797.blog.163.com/blog/static/1007689142014524115743806/
http://www.cnblogs.com/imoing/p/dockervolumes.html
https://github.com/docker/fig/issues/88
版權聲明:本文為博主原創(chuàng)文章,未經(jīng)博主允許不得轉載。