ubuntu安裝docker{ubuntu16.04下安裝docker}

   1、開始安裝

 第一步:   因爲apt官方庫裏的docker版本可能比較舊,因此先卸載可能存在的舊版本:

$ sudo apt-get remove docker docker-engine docker-ce docker.io


 第二步、更新apt包索引:

                $ sudo apt-get update

第三步、  安裝如下包以使apt能夠經過HTTPS使用存儲庫(repository):

               $ sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common

第四步、 添加Docker官方的GPG密鑰:

                $ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -

 第五步: 使用下面的命令來設置stable存儲庫:

                $ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

第六步:     再更新一下apt包索引:

                $ sudo apt-get update

 第七步:    安裝最新版本的Docker CE:

                $ sudo apt-get install -y docker-ce

    在生產系統上,可能會須要應該安裝一個特定版本的Docker CE,而不是老是使用最新版本:

第八步:列出可用的版本:
            $ apt-cache madison docker-ce
選擇要安裝的特定版本,第二列是版本字符串,第三列是存儲庫名稱,它指示包來自哪一個存儲庫,以及擴展它的穩定性級別。要安裝一個特定的版本,將版本字符串附加到包名中,並經過等號(=)分隔它們:php

 


驗證docker

    查看docker服務是否啓動:

$ systemctl status docker

    1

    若未啓動,則啓動docker服務:

$ sudo systemctl start docker

    1

    經典的hello world:

$ sudo docker run hello-world $ sudo apt-get install docker-ce=<VERSION>




2、運行報錯:解決方案css


昨天在使用docker 時,將 image 文件從倉庫抓取到本地一直報錯,通過嘗試,終於得以解決。

錯誤信息以下:python

[root@archlinux ~]# docker image pull library/hello-world Using default tag: latest Error response from daemon: Get https://registry-1.docker.io/v2/library/hello-world/manifests/latest: dial tcp 52.20.146.203:443: i/o timeout

 

或者:mysql

[root@archlinux quanxj]# docker image pull library/hello-world Using default tag: latest latest: Pulling from library/hello-world ca4f61b1923c: Pull complete error pulling image configuration: Get https://registry-1.docker.io/v2/library/hello-world/blobs/sha256:f2a91732366c0332ccd7afd2a5c4ff2b9af81f549370f7a19acd460f87686bc7: dial tcp 35.169.231.249:443: i/o timeout

解決方法以下:
第一步:經過dig @114.114.114.114 registry-1.docker.io找到可用IPlinux

[root@archlinux ~]# dig @114.114.114.114 registry-1.docker.io ; <<>> DiG 9.12.0 <<>> @114.114.114.114 registry-1.docker.io ; (1 server found) ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 37534 ;; flags: qr rd ra; QUERY: 1, ANSWER: 8, AUTHORITY: 0, ADDITIONAL: 1 ;; OPT PSEUDOSECTION: ; EDNS: version: 0, flags:; udp: 4096 ; COOKIE: 88f87a15f4ca45dc (echoed) ;; QUESTION SECTION: ;registry-1.docker.io. IN A ;; ANSWER SECTION: registry-1.docker.io. 30 IN A 34.200.28.105 registry-1.docker.io. 30 IN A 52.22.181.254 registry-1.docker.io. 30 IN A 35.169.231.249 registry-1.docker.io. 30 IN A 52.5.185.86 registry-1.docker.io. 30 IN A 54.164.230.151 registry-1.docker.io. 30 IN A 34.200.90.16 registry-1.docker.io. 30 IN A 52.20.146.203 registry-1.docker.io. 30 IN A 52.206.156.207 ;; Query time: 116 msec ;; SERVER: 114.114.114.114#53(114.114.114.114) ;; WHEN: 四 3月 08 09:27:12 CST 2018 ;; MSG SIZE rcvd: 189

 

第二步:嘗試修改/etc/hosts強制docker.io相關的域名解析到其它可用IPsql

vim /etc/hosts
  • 1

添加一個可用IP:docker

52.5.185.86 registry-1.docker.io
  • 1

保存以後重試:json

[root@archlinux quanxj]# docker image pull library/hello-world Using default tag: latest latest: Pulling from library/hello-world ca4f61b1923c: Already exists Digest: sha256:083de497cff944f969d8499ab94f07134c50bcf5e6b9559b27182d3fa80ce3f7 Status: Downloaded newer image for hello-world:latest

驗證:ubuntu

[root@archlinux quanxj]# docker image ls REPOSITORY TAG IMAGE ID CREATED SIZE hello-world latest f2a91732366c 3 months ago 1.85kB


3、若是還不行,則用以下方法:

[root@teddy /]# docker search ubuntu
Error response from daemon: Get https://index.docker.io/v1/search?q=ubuntu: read tcp 52.200.132.201:443: i/o timeout


docker在中國已經有了倉庫:https://www.docker-cn.com/registry-mirror


根據上面網站提供的修改方法。


進入/etc/docker

查看有沒有 daemon.json。這是docker默認的配置文件。

若是沒有新建touch daemon.json,若是有,則修改。


[root@teddy docker]# vi daemon.json
{
  "registry-mirrors": ["https://registry.docker-cn.com"]
}

保存退出。


重啓docker服務

service docker restart

成功!


[root@teddy docker]# docker search ubuntu
NAME                               DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
ubuntu                             The official build of ubuntu.                   3732      [OK]       
ansible/ubuntu-ansible            Ansible on ubuntu                              102                  [OK]
jdeathe/ubuntu-ssh                 ubuntu-6 6.9 x86_64 / ubuntu 7.4.1708 x8...   87                   [OK]
tutum/ubuntu                       Simple ubuntu docker image with SSH access      33                   
imagine10255/ubuntu6-lnmp-php56    ubuntu6-lnmp-php56                              31                   [OK]
gluster/gluster-ubuntu             Official GlusterFS Image [ ubuntu +  Glu...   20                   [OK]
kinogmt/ubuntu-ssh                 ubuntu with SSH                                 17                   [OK]
ubuntu/php-56-ubuntu              Platform for building and running PHP 5.6 ...   10                   
openshift/base-ubuntu             A ubuntu derived base image for Source-To...   10                   
ubuntu/python-35-ubuntu           Platform for building and running Python 3...   9                    
openshift/mysql-55-ubuntu         DEPRECATED: A ubuntu based MySQL v5.5 ima...   6                    
openshift/jenkins-2-ubuntu        A ubuntu based Jenkins v2.x image for use...   5                    
openshift/ruby-20-ubuntu          DEPRECATED: A ubuntu based Ruby v2.0 imag...   3                    
darksheer/ubuntu                   Base ubuntu Image -- Updated hourly             3                    [OK]
indigo/ubuntu-maven                Vanilla ubuntu 7 with Oracle Java Developm...   1                    [OK]
openshift/php-55-ubuntu           DEPRECATED: A ubuntu based PHP v5.5 image...   1                    
pivotaldata/ubuntu-gpdb-dev        ubuntu image for GPDB development. Tag nam...   1                    
pivotaldata/ubuntu-mingw           Using the mingw toolchain to cross-compile...   1                    
miko2u/ubuntu6                     ubuntu6 日本語環境                                   1                    [OK]
blacklabelops/ubuntu               ubuntu Base Image! Built and Updates Daily!     1                    [OK]
smartentry/ubuntu                  ubuntu with smartentry                          0                    [OK]
pivotaldata/ubuntu                 Base ubuntu, freshened up a little with a ...   0                    
openshift/wildfly-101-ubuntu     A ubuntu based WildFly v10.1 image for us...   0                    
jameseckersall/sonarr-ubuntu       Sonarr on ubuntu 7                              0                    [OK]
pivotaldata/ubuntu-gcc-toolchain   ubuntu with a toolchain, but unaffiliated ...   0                    
[root@teddy docker]#
daemon.json
相關文章
相關標籤/搜索