在Linux上安裝docker和docker-compose

安裝docker

在終端中執行如下命令安裝:linux

$ curl -sSL https://get.daocloud.io/docker | sh

出現如下內容,說明安裝成功了:git

Client:
 Version:      17.04.0-ce
 API version:  1.28
 Go version:   go1.7.5
 Git commit:   4845c56
 Built:        Mon Apr  3 18:07:42 2017
 OS/Arch:      linux/amd64

Server:
 Version:      17.04.0-ce
 API version:  1.28 (minimum version 1.12)
 Go version:   go1.7.5
 Git commit:   4845c56
 Built:        Mon Apr  3 18:07:42 2017
 OS/Arch:      linux/amd64
 Experimental: false

If you would like to use Docker as a non-root user, you should now consider
adding your user to the "docker" group with something like:

  sudo usermod -aG docker zhangdaofeng

Remember that you will have to log out and back in for this to take effect!

確認docker是否成功安裝了:github

$ sudo docker run hello-world

反饋以下,則安裝成功。docker

Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
78445dd45222: Pull complete 
Digest: sha256:c5515758d4c5e1e838e9cd307f6c6a0d620b5e07e6f927b07d05f6d12a1ac8d7
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

To generate this message, Docker took the following steps:
 1. The Docker client contacted the Docker daemon.
 2. The Docker daemon pulled the "hello-world" image from the Docker Hub.
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://cloud.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/engine/userguide/

安裝docker-compose

Docker Compose是一個用來定義和運行復雜應用的Docker工具。使用Compose,你能夠在一個文件中定義一個多容器應用,而後使用一條命令來啓動你的應用,完成一切準備工做。shell

一個使用Docker容器的應用,一般由多個容器組成。使用Docker Compose,再也不須要使用shell腳原本啓動容器。在配置文件中,全部的容器經過services來定義,而後使用docker-compose腳原本啓動、中止和重啓應用,以及應用中的服務以及全部依賴服務的容器。ubuntu

運行下面的命令來安裝 Compose:bash

curl -L https://github.com/docker/compose/releases/download/1.12.0/docker-compose-`uname -s`-`uname -m` > /usr/local/bin/docker-compose
chmod +x /usr/local/bin/docker-compose

**注意:**若是你在安裝的時候出現了 「Permission denied」 的錯誤信息,這說明你的 /usr/local/bin 目錄是不可寫的,你須要使用超級用戶來安裝。運行 sudo -i , 而後運行上邊的兩個命令,而後 exit 退出。app

也能夠使用pip安裝:curl

$ sudo pip install -U docker-compose

到這裏安裝就結束了;Compose已經安裝完成。你能夠使用 docker-compose --version 來進行測試。ide

相關文章
相關標籤/搜索