手把手ubuntu18.04安装docker步骤

2022/7/2 5:22:17

本文主要是介绍手把手ubuntu18.04安装docker步骤,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

    01.业务背景

    使用ubuntu18.04来安装docker

   

    02.安装什么

    安装docker-engine和安装docker-compose


    03.官网地址

    docker的官网:https://www.docker.com

    ubuntu18.04安装docker的参考地址:

    https://docs.docker.com/engine/install/ubuntu/

   
    参考文章:Install Docker Engine on Ubuntu

    无须安装docker-desktop


    04.安装docker

    步骤01.清理旧版

    如果以前安装过docker,可以将旧版本进行卸载(one line).

    卸载01:

    sudo apt-get remove docker docker-engine docker.io containerd runc

    卸载02:

    sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin

    卸载03:

    sudo rm -rf /var/lib/docker

    sudo rm -rf /var/lib/containerd


    步骤02.创建仓库

    如果你是第一次安装docker,那么需要安装docker仓库.

    Update the apt package index and install packages to allow apt to use a repository over HTTPS:

    执行2.1: sudo apt-get update

    执行2.2: (one line)

    sudo apt-get install ca-certificates curl gnupg lsb-release

   

    Add Docker’s official GPG key:

    执行2.3: sudo mkdir -p /etc/apt/keyrings

    执行2.4:

    curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

   

    Use the following command to set up the repository:

    执行2.5: (one line)

    echo "deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu  $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

   

    需要确认不同的操作系统版本号,配置的数据根本不同.

    使用ubuntu18.04,因此配置是bionic.

    sudo gedit /etc/apt/sources.list.d/docker.list

    deb [arch=amd64 signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu bionic stable


    步骤03.下载引擎

    Install Docker Engine.

    Update the apt package index, and install the latest version of Docker Engine, containerd, and Docker Compose, or go to the next step to install a specific version:

    执行3.1: sudo apt-get update

    执行3.2: -- 安装了三个组件.

    sudo apt-get install docker-ce docker-ce-cli containerd.io docker-compose-plugin

      

    To install a specific version of Docker Engine,list the available versions in the repo, then select and install:

    a. List the versions available in your repo:

    执行3.3:

    apt-cache madison docker-ce

   

    

   

    b. Install a specific version using the version string from the second column.for example, 5:20.10.16~3-0~ubuntu-jammy.

    执行3.4的命令参考:

    sudo apt-get install docker-ce=<VERSION_STRING> docker-ce-cli=<VERSION_STRING> containerd.io docker-compose-plugin

    参考案例:

    docker-ce | 5:20.10.17~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages

    docker-ce | 5:20.10.16~3-0~ubuntu-bionic | https://download.docker.com/linux/ubuntu bionic/stable amd64 Packages

    执行3.4:

    sudo apt-get install docker-ce=5:20.10.17~3-0~ubuntu-bionic docker-ce-cli=5:20.10.17~3-0~ubuntu-bionic containerd.io docker-compose-plugin


    步骤04.执行镜像

    Verify that Docker Engine is installed correctly by running the hello-world image.

    执行4.1:sudo docker run hello-world


    This command downloads a test image and runs it in a container. When the container runs, it prints a message and exits.Docker Engine 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.

    步骤05.启动镜像

    01.如何启动docker

    执行命令: sudo systemctl start docker

    02.查看docker进程

    执行命令: ps -ef | grep docker

    03.执行镜像

    执行命令: sudo docker run hello-world

   

   

   
    05.安装docker-compose

    步骤01.查看python

    pip3是Python中的标准库管理器,它允许你安装和管理不属于 Python标准库的其它软件包.因为在ubuntu中可能安装python2或者python3.可能存在不同的pip工具.

    本文主要使用python3来做验证.

    验证:pip3 -V

    安装: sudo apt install python3-pip

    更新:pip3 install --upgrade pip


    执行验证和更新命令.

    列出已安装的包: pip3 list


    步骤02.安裝docker-compose

    执行安装: pip install docker-compose



这篇关于手把手ubuntu18.04安装docker步骤的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程