ubuntu 安装 docker以及docker-compose

Docker is supported on these Ubuntu operating systems:

  • Ubuntu Xenial 16.04 (LTS)
  • Ubuntu Wily 15.10
  • Ubuntu Trusty 14.04 (LTS)
  • Ubuntu Precise 12.04 (LTS)
准备:


update your apt sources:


Docker’s APT repository contains Docker 1.7.1 and higher. To set APT to use packages from the Docker repository:

  1. Log into your machine as a user with sudo or root privileges.

  2. Open a terminal window.

  3. Update package information, ensure that APT works with the https method, and that CA certificates are installed.

    $ sudo apt-get update
    $ sudo apt-get install apt-transport-https ca-certificates
    
  4. Add the new GPG key.

    $ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
    
  5. Find the entry for your Ubuntu operating system.

    The entry determines where APT will search for packages. The possible entries are:

    Ubuntu version Repository
    Precise 12.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-precise main
    Trusty 14.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-trusty main
    Wily 15.10 deb https://apt.dockerproject.org/repo ubuntu-wily main
    Xenial 16.04 (LTS) deb https://apt.dockerproject.org/repo ubuntu-xenial main

    Note: Docker does not provide packages for all architectures. Binary artifacts are built nightly, and you can download them from https://master.dockerproject.org. To install docker on a multi-architecture system, add an [arch=...] clause to the entry. Refer to Debian Multiarch wiki for details.

  6. Run the following command, substituting the entry for your operating system for the placeholder <REPO>.

    $ echo "<REPO>" | sudo tee /etc/apt/sources.list.d/docker.list
    
  7. Update the APT package index.

    $ sudo apt-get update
    
  8. Verify that APT is pulling from the right repository.

    When you run the following command, an entry is returned for each version of Docker that is available for you to install. Each entry should have the URL https://apt.dockerproject.org/repo/. The version currently installed is marked with ***.The output below is truncated.

    $ apt-cache policy docker-engine
    
      docker-engine:
        Installed: 1.12.2-0~trusty
        Candidate: 1.12.2-0~trusty
        Version table:
       *** 1.12.2-0~trusty 0
              500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
              100 /var/lib/dpkg/status
           1.12.1-0~trusty 0
              500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
           1.12.0-0~trusty 0
              500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
           1.11.2-0~trusty 0
              500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
           1.11.1-0~trusty 0
              500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
    

    From now on when you run apt-get upgradeAPT pulls from the new repository.

安装与测试

Then, install Docker using the following:

  1. Log into your Ubuntu installation as a user with sudo privileges.

  2. Update your APT package index.

     $ sudo apt-get update
    
  3. Install Docker.

     $ sudo apt-get install docker-engine
    
  4. Start the docker daemon.

     $ sudo service docker start
    
  5. Verify docker is installed correctly.

     $ sudo docker run hello-world
    

    This command downloads a test image and runs it in a container. When the container runs, it prints an informational message. Then, it exits.

o create the docker group and add your user:

  1. Log into Ubuntu as a user with sudo privileges.

  2. Create the docker group.

     $ sudo groupadd docker
    
  3. Add your user to docker group.

     $ sudo usermod -aG docker $USER
    
  4. Log out and log back in.

    This ensures your user is running with the correct permissions.

  5. Verify your work by running docker without sudo.

     $ docker run hello-world



ubuntu16.04为例进行安装:
$ sudo apt-get -yqq update #更新apt-get源
$ sudo apt-get -yqq install apt-transport-https ca-certificates
$ sudo apt-key adv --keyserver hkp://ha.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
$ echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
$ sudo apt-get -yqq update
$ apt-cache policy docker-engine#可选
$ sudo apt-get -yqq install linux-image-extra-$(uname -r) linux-image-extra-virtual#可选
$ sudo apt-get -yqq update
$ sudo apt-get -yqq install docker-engine
$ sudo service docker start #or sudo docker daemon & or docker daemon & or systemctl start docker 都要以root用户执行才可以。
$ sudo docker run hello-world #运行hello-world镜像
$ sudo systemctl enable docker#配置开机启动

####
$ sudo groupadd docker #这一步可以不用,默认会创建docker用户组
$ sudo usermod -aG docker $USER #加入docker用户组,该组的用户才可以 sudo docker 执行docker命令




一种简单的安装docker的方法:
$sudo curl -fsSL https://get.docker.com/ | sh
安装docker-compose:
$sudo apt-get -yqq install aptitude
$sudo aptitude -y install python-pip
$sudo pip install docker-compose
$sudo docker-compose version






  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值