欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

docker 入坑1

程序员文章站 2023-12-25 15:05:33
本文是记录一下学习docker的过程,希望可以帮助到入门的朋友。 系统:ubuntu16.04 docker:18.09 打开官网:https://docs.docker.com/install/linux/docker-ce/ubuntu/ OS requirements To install D ......

本文是记录一下学习docker的过程,希望可以帮助到入门的朋友。

系统:ubuntu16.04

docker:18.09

打开官网:https://docs.docker.com/install/linux/docker-ce/ubuntu/

os requirements

to install docker engine - community, you need the 64-bit version of one of these ubuntu versions:

  • disco 19.04
  • cosmic 18.10
  • bionic 18.04 (lts)
  • xenial 16.04 (lts)

docker engine - community is supported on x86_64 (or amd64), armhf, arm64, s390x (ibm z), and ppc64le (ibm power) architectures.

查看我们的系统是否符合最新版docker安装的要求:

1 mantishell@zkl:~$ uname -a
2 linux zkl 4.15.0-55-generic #60~16.04.2-ubuntu smp thu jul 4 09:03:09 utc 2019 x86_64 x86_64 x86_64 gnu/linux
3 mantishell@zkl:~$ lsb_release -a
4 no lsb modules are available.
5 distributor id:    ubuntu
6 description:    ubuntu 16.04.6 lts
7 release:    16.04
8 codename:    xenial

符合最后一条:xenial 16.04 (lts)

如果不符合,怎么办呢?不要灰心,可以安装历史版本。官网也有说明。

install docker engine - community

you can install docker engine - community in different ways, depending on your needs:

  • most users set up docker’s repositories and install from them, for ease of installation and upgrade tasks. this is the recommended approach.

  • some users download the deb package and and manage upgrades completely manually. this is useful in situations such as installing docker on air-gapped systems with no access to the internet.

  • in testing and development environments, some users choose to use automated to install docker.

install using the repository

before you install docker engine - community for the first time on a new host machine, you need to set up the docker repository. afterward, you can install and update docker from the repository.

set up the repository

  1. update the apt package index:

    $ sudo apt-get update
    
  2. install packages to allow apt to use a repository over https:

    $ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
    
  3. add docker’s official gpg key:

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

    verify that you now have the key with the fingerprint 9dc8 5822 9fc7 dd38 854a e2d8 8d81 803c 0ebf cd88, by searching for the last 8 characters of the fingerprint.

    $ sudo apt-key fingerprint 0ebfcd88
        
    pub   rsa4096 2017-02-22 [scea]
          9dc8 5822 9fc7 dd38 854a  e2d8 8d81 803c 0ebf cd88
    uid           [ unknown] docker release (ce deb) <docker@docker.com>
    sub   rsa4096 2017-02-22 [s]
    
  4. use the following command to set up the stable repository. to add the nightly or test repository, add the word nightly or test (or both) after the word stable in the commands below. learn about nightly and test channels.

    note: the lsb_release -cs sub-command below returns the name of your ubuntu distribution, such as xenial. sometimes, in a distribution like linux mint, you might need to change $(lsb_release -cs) to your parent ubuntu distribution. for example, if you are using linux mint tessa, you could use bionic. docker does not offer any guarantees on untested and unsupported ubuntu distributions.

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

install docker engine - community

  1. update the apt package index.

    $ sudo apt-get update
    
  2. install the latest version of docker engine - community and containerd, or go to the next step to install a specific version:

    $ sudo apt-get install docker-ce docker-ce-cli containerd.io
    

    got multiple docker repositories?

    if you have multiple docker repositories enabled, installing or updating without specifying a version in the apt-get install or apt-get update command always installs the highest possible version, which may not be appropriate for your stability needs.

  3. to install a specific version of docker engine - community, list the available versions in the repo, then select and install:

    a. list the versions available in your repo:

    $ apt-cache madison docker-ce
    
      docker-ce | 5:18.09.1~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu  xenial/stable amd64 packages
      docker-ce | 5:18.09.0~3-0~ubuntu-xenial | https://download.docker.com/linux/ubuntu  xenial/stable amd64 packages
      docker-ce | 18.06.1~ce~3-0~ubuntu       | https://download.docker.com/linux/ubuntu  xenial/stable amd64 packages
      docker-ce | 18.06.0~ce~3-0~ubuntu       | https://download.docker.com/linux/ubuntu  xenial/stable amd64 packages
      ...
    

    b. install a specific version using the version string from the second column, for example, 5:18.09.1~3-0~ubuntu-xenial.

    $ sudo apt-get install docker-ce=<version_string> docker-ce-cli=<version_string> containerd.io
    
  4. verify that docker engine - community is installed correctly by running the hello-world image.

    $ 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 and exits.

docker engine - community is installed and running. the docker group is created but no users are added to it. you need to use sudo to run docker commands. continue to linux postinstall to allow non-privileged users to run docker commands and for other optional configuration steps.

upgrade docker engine - community

to upgrade docker engine - community, first run sudo apt-get update, then follow the , choosing the new version you want to install.

install from a package

if you cannot use docker’s repository to install docker engine - community, you can download the .deb file for your release and install it manually. you need to download a new file each time you want to upgrade docker.

  1. go to , choose your ubuntu version, browse to pool/stable/, choose amd64, armhf, arm64, ppc64el, or s390x, and download the .deb file for the docker engine - community version you want to install.

    note: to install a nightly package, change the word stable in the url to nightly. learn about nightly and test channels.

  2. install docker engine - community, changing the path below to the path where you downloaded the docker package.

    $ sudo dpkg -i /path/to/package.deb
    

    the docker daemon starts automatically.

  3. verify that docker engine - community is installed correctly by running the hello-world image.

    $ 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 and exits.

docker engine - community is installed and running. the docker group is created but no users are added to it. you need to use sudo to run docker commands. continue to post-installation steps for linux to allow non-privileged users to run docker commands and for other optional configuration steps.

upgrade docker engine - community

to upgrade docker engine - community, download the newer package file and repeat the , pointing to the new file.

install using the convenience script

docker provides convenience scripts at and for installing edge and testing versions of docker engine - community into development environments quickly and non-interactively. the source code for the scripts is in the . using these scripts is not recommended for production environments, and you should understand the potential risks before you use them:

  • the scripts require root or sudo privileges to run. therefore, you should carefully examine and audit the scripts before running them.
  • the scripts attempt to detect your linux distribution and version and configure your package management system for you. in addition, the scripts do not allow you to customize any installation parameters. this may lead to an unsupported configuration, either from docker’s point of view or from your own organization’s guidelines and standards.
  • the scripts install all dependencies and recommendations of the package manager without asking for confirmation. this may install a large number of packages, depending on the current configuration of your host machine.
  • the script does not provide options to specify which version of docker to install, and installs the latest version that is released in the “edge” channel.
  • do not use the convenience script if docker has already been installed on the host machine using another mechanism.

this example uses the script at to install the latest release of docker engine - community on linux. to install the latest testing version, use instead. in each of the commands below, replace each occurrence of get with test.

warning:

always examine scripts downloaded from the internet before running them locally.

$ curl -fssl https://get.docker.com -o get-docker.sh
$ sudo sh get-docker.sh

<output truncated>

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 your-user

remember to log out and back in for this to take effect!

warning:

adding a user to the “docker” group grants them the ability to run containers which can be used to obtain root privileges on the docker host. refer to docker daemon attack surface for more information.

docker engine - community is installed. it starts automatically on deb-based distributions. on rpm-based distributions, you need to start it manually using the appropriate systemctl or service command. as the message indicates, non-root users can’t run docker commands by default.

upgrade docker after using the convenience script

if you installed docker using the convenience script, you should upgrade docker using your package manager directly. there is no advantage to re-running the convenience script, and it can cause issues if it attempts to re-add repositories which have already been added to the host machine.

uninstall docker engine - community

  1. uninstall the docker engine - community package:

    $ sudo apt-get purge docker-ce
    
  2. images, containers, volumes, or customized configuration files on your host are not automatically removed. to delete all images, containers, and volumes:

    $ sudo rm -rf /var/lib/docker
    

you must delete any edited configuration files manually.

上面是官方给的步骤,相信大家按照步骤一步步进行,也能搭建起来。这里呢我记录一下,我的操作步骤:

  1. update the apt package index:
    $ sudo apt-get update
    
  2. install packages to allow apt to use a repository over https:
    $ sudo apt-get install apt-transport-https ca-certificates curl gnupg-agent software-properties-common
    

     

  3. add docker`s offical gpg key:
    $ curl -fssl https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
    

     

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

     

  5. install the latest version of docker engine - community and containerd, or go to the next step to install a specific version:
    $ sudo apt-get install docker docker-compose
    

     

  6. to install a specific version of docker engine - community, list the available versions in the repo, then select and install:
    1. list the versions available in your repo:
      $ apt-cache madison docker-ce
      

       

    2. install a specific version using the version string from the second column, for example, 5:18.09.1~3-0~ubuntu-xenial
      $ sudo apt-get install docker-ce=<version_string> docker-ce-cli=<version_string> containerd.io $ sudo apt-get install docker-ce=5:18.09.0~3-0~ubuntu-xenial docker-ce-cli=5:18.09.0~3-0~ubuntu-xenial containerd.io
      

       

  7. verify that docker engine - community is installed correctly by running the hello-world image.
    $ sudo docker run hello-world
    

     

 

上一篇:

下一篇: