Docker in Ubuntu20.04

XianxinMao 2021-07-28 10:28:36

docker install

Uninstall old versions

Older versions of Docker were called docker, docker.io, or docker-engine. If these are installed, uninstall them:

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

Install using the repository

Before you install Docker Engine 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 and install packages to allow apt to use a repository over HTTPS:

sudo apt-get update
​
sudo apt-get install \
    apt-transport-https \
    ca-certificates \
    curl \
    gnupg \
    lsb-release
  1. Add Docker’s official GPG key:

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg
  1. 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.

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

Install Docker Engine

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

sudo apt-get update
​
sudo apt-get install docker-ce docker-ce-cli containerd.io
  1. Verify that Docker Engine is installed correctly by running the hello-world image.

sudo docker run hello-world

nvidia-docker install

Setting up Docker

Docker-CE on Ubuntu can be setup using Docker’s official convenience script:

curl https://get.docker.com | sh \
  && sudo systemctl --now enable docker

Setting up NVIDIA Container Toolkit

Setup the stable repository and the GPG key:

distribution=$(. /etc/os-release;echo $ID$VERSION_ID) \
   && curl -s -L https://nvidia.github.io/nvidia-docker/gpgkey | sudo apt-key add - \
   && curl -s -L https://nvidia.github.io/nvidia-docker/$distribution/nvidia-docker.list | sudo tee /etc/apt/sources.list.d/nvidia-docker.list

Install the nvidia-docker2 package (and dependencies) after updating the package listing:

sudo apt-get update
​
sudo apt-get install -y nvidia-docker2

Restart the Docker daemon to complete the installation after setting the default runtime:

sudo systemctl restart docker

At this point, a working setup can be tested by running a base CUDA container:

sudo docker run --rm --gpus all nvidia/cuda:11.0-base nvidia-smi

docker command

HOW TO CREATE A DOCKER IMAGE FROM A CONTAINER

The Docker create command will create a new container for us from the command line:

sudo docker create --name nginx_base -p 80:80 nginx:alpine

Inspect Images

sudo docker images -a

Inspect Containers

sudo docker ps -a

We will use the docker cp command to copy this file onto the running container

sudo docker cp index.html nginx_base:/usr/share/nginx/html/index.html

Create an Image From a Container

sudo docker commit nginx_base hi_mom_nginx

python install

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.6

Change the Python3 default version in Ubuntu

sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.5 1
sudo update-alternatives --install /usr/bin/python python /usr/bin/python3.6 2
​
sudo update-alternatives --config python

python3-pip install

sudo apt install python3-pip
echo "alias pip=pip3" >> ~/.bash_aliases
source ~/.bash_aliases
alias pip='python3.6 -m pip'
pip install --upgrade pip
...全文
18 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

7,340

社区成员

发帖
与我相关
我的任务
社区描述
因为缘分,所以猿粉! 这里有“入门级选手”必备的成长路线图,为“程序员后备队”提供技术大咖直播指导,丰富的学习资料已经等候多时,请查收! 陪伴猿粉共同成长,提升技术不在话下;右边扫码关注微信公众号。
其他 其他
社区管理员
  • 高校俱乐部
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

       2021年“C站百所高校巡讲” “C站名企参观”等活动,火热报名中, 与CSDN创始人蒋涛、各路技术大咖面对面!

       现招募CSDN高校俱乐部的部长并组建本校CSDN高校俱乐部,我们希望你是高校在校生且是IT技术爱好者,校内社交圈,有强烈的责任心,熟悉社团工作,有校园活动组织经验,在高校能够建立长足发展的学习型俱乐部,我们期待您的加入,CSDN高校俱乐部将赋予以下权益:

  • 高校巡讲:骨灰级专家线下巡讲
  • 线上直播:技术大咖线上分享
  • 线下沙龙:学习精英线下沙龙讨论
  • 学习小组:任务驱动,免费学习
  • 能力认证:对标大厂,高薪就业
  • 技术竞赛:竞赛选拔,实战演练
  • 企业游学:到大厂参观并学习
  • 企业招聘:面向俱乐部成员专属招聘
  • 专属博客:给各俱乐部搭建社区云
  • 电子书卡:给俱乐部成员提供学习资源
  • 组织logo:设计旗帜,活动宣传

 联系方式:

  • 电话:张老师-17734567851(同微)
  • 邮箱:student@csdn.net
  • Q Q:1218227747

试试用AI创作助手写篇文章吧