ubuntu 安装 docker以及docker-compose

前端之家收集整理的这篇文章主要介绍了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’sAPTrepository contains Docker 1.7.1 and higher. To setAPTto use packages from the Docker repository:

  1. Log into your machine as a user withsudoorrootprivileges.

  2. Open a terminal window.

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

    $ sudo apt-get update
    $ sudo apt-get install apt-transport-https ca-certificates
  4. Add the newGPGkey.

    $ 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:

    Xenial 16.04 (LTS)
    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
    deb https://apt.dockerproject.org/repo ubuntu-xenial main
    @H_301_135@

    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 toDebian Multiarch wikifor 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 theAPTpackage index.

    $ sudo apt-get update
  8. Verify thatAPTis 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 URLhttps://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: -0~trusty
        Version table:
       *** -0~trusty 0
              500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
              100 /var/lib/dpkg/status
           .1500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages
           .01.11500 https://apt.dockerproject.org/repo/ ubuntu-trusty/main amd64 Packages

    From now on when you runapt-get upgrade,APTpulls from the new repository.

安装与测试

Then,install Docker using the following:

  1. Log into your Ubuntu installation as a user withsudoprivileges.

  2. Update yourAPTpackage index.

    $ sudo apt-get update
  3. Install Docker.

    $ sudo apt-get install docker-engine
  4. Start thedockerdaemon.

    $ sudo service docker start
  5. Verifydockeris 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 thedockergroup and add your user:

  1. Log into Ubuntu as a user withsudoprivileges.

  2. Create thedockergroup.

    $ sudo groupadd docker
  3. Add your user to$ sudo usermod -aG docker $USER

  • Log out and log back in.

    This ensures your user is running with the correct permissions.

  • Verify your work by runningdockerwithoutsudo.

    $ 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 docker start 都要以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



    猜你在找的Ubuntu相关文章