Docker是PaaS供應商dotCloud開源的一個基於LXC 的高級容器引擎,源代碼託管在 GitHub 上, 基於Go語言開發並聽從Apache 2.0協議開源。Docker提供了一種在安全、可重複的環境中自動部署軟件的方式。node
關於Docker的架構,查看官方介紹。 linux
Docker致力於提供:docker
1. 簡單、輕量的建模方式安全
2. 開發運維職責的邏輯分離,下降開發與生產環境的不一致性。服務器
3. 快速高效的開發生命週期網絡
4. 面向服務的架構,推薦單個容器只運行一個應用程序或進程架構
Docker核心組件:app
Docker客戶端和服務器運維
Docker鏡像socket
Registry
Docker容器
Docker技術組件:
1) libcontainer,一個原生的linux 容器格式
2) Linux 內核的命名空間(namespace),用戶隔離文件系統、進程和網絡
以下安裝適用於Redhat操做系統。
安裝方式有兩種:使用yum在線安裝,或者使用安裝包安裝。
使用yum方式安裝
1 //1 更新yum 安裝包index 2 $ sudo yum makecache fast 3 4 //2. 安裝docker最新版本 5 $ sudo yum -y install docker-engine 6 7 // 或者安裝特定版本 8 $ yum list docker-engine.x86_64 --showduplicates |sort -r 9 $ sudo yum -y install docker-engine-<VERSION_STRING>
使用安裝包安裝
1 下載對應操做系統版本的包,好比對應RHCE的rpm包 2 安裝 $ sudo yum install package.rpm
$ sudo systemctl start docker
驗證Docker是否安裝成功
$ sudo docker run hello-world
使用docker version查看版本
更多參考官方文檔。
docker
Usage: docker COMMAND A self-sufficient runtime for containers Options: --config string Location of client config files (default "/Users/liuchun/.docker") -D, --debug Enable debug mode --help Print usage -H, --host list Daemon socket(s) to connect to (default []) -l, --log-level string Set the logging level ("debug", "info", "warn", "error", "fatal") (default "info") --tls Use TLS; implied by --tlsverify --tlscacert string Trust certs signed only by this CA (default "/Users/liuchun/.docker/ca.pem") --tlscert string Path to TLS certificate file (default "/Users/liuchun/.docker/cert.pem") --tlskey string Path to TLS key file (default "/Users/liuchun/.docker/key.pem") --tlsverify Use TLS and verify the remote -v, --version Print version information and quit Management Commands: checkpoint Manage checkpoints container Manage containers image Manage images network Manage networks node Manage Swarm nodes plugin Manage plugins secret Manage Docker secrets service Manage services stack Manage Docker stacks swarm Manage Swarm system Manage Docker volume Manage volumes 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 between a container and the local filesystem create Create a new container deploy Deploy a new stack or update an existing stack 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 Export a container's filesystem as a tar archive history Show the history of an image images List images import Import the contents from a tarball to create a filesystem image info Display system-wide information inspect Return low-level information on Docker objects kill Kill one or more running containers load Load an image from a tar archive or STDIN login Log in to a Docker registry logout Log out from a Docker registry logs Fetch the logs of a container pause Pause all processes within one or more containers port List port mappings or a specific mapping for the container ps List containers pull Pull an image or a repository from a registry push Push an image or a repository to a registry rename Rename a container restart Restart one or more containers rm Remove one or more containers rmi Remove one or more images run Run a command in a new container save Save one or more images to a tar archive (streamed to STDOUT by default) search Search the Docker Hub for images start Start one or more stopped containers stats Display a live stream of container(s) resource usage statistics stop Stop one or more running containers tag Create a tag TARGET_IMAGE that refers to SOURCE_IMAGE top Display the running processes of a container unpause Unpause all processes within one or more containers update Update configuration of one or more containers version Show the Docker version information wait Block until one or more containers stop, then print their exit codes Run 'docker COMMAND --help' for more information on a command.
docker command --help
,例如啓動命令docker run --help
Docker配置服務
RHCE7 參考https://docs.docker.com/engine/admin/
運行一條命令的example
# docker run busybox echo "Hello, this is new msg" # docker ps //查看容器 # docker ps -a // 查看到已經中止的容器
docker run: 命令用來建立運行容器
docker ps:
用來查看正在運行的容器列表
幾個最經常使用的參數:
-a
:查看全部容器,含中止運行的-l
:查看剛啓動的容器-q
:只顯示容器IDdocker start: 啓動容器
咱們能夠經過 docker attach
鏈接到某個正在運行的container。
docker stop: 中止容器
docker inspect: 查看Docker容器或鏡像的一些內部信息
docker rm: 刪除容器操做,默認不能夠刪除運行的容器,但提供了強制刪除的參數-f
docker top: 查看容器中運行的進程信息,顯示容器中進程的PID,UID,PPID,時間,tty等信息。
docker images: 查看鏡像列表
其中:
latest
docker pull: 獲取鏡像, 從Docker Hub上pull某一個鏡像
建立鏡像: 最經常使用的是寫一個Dockerfile,從Dockerfile裏建立新的鏡像。
清理鏡像:使用docker rmi來刪除鏡像,刪除鏡像前要用docker rm刪除對應的container