当前位置:首页 > 行业动态 > 正文

如何在Debian中安装并使用Docker容器

在Debian中安装并使用Docker容器

Docker是一个开源的容器化平台,它允许开发者将应用程序及其依赖项打包到一个可移植的容器中,然后在任何支持Docker的系统上运行,本文将介绍如何在Debian系统中安装和配置Docker,以及如何使用Docker容器。

安装Docker

1、更新系统软件包列表

在开始安装Docker之前,首先需要更新Debian系统的软件包列表,打开终端,输入以下命令:

sudo aptget update

2、安装依赖项

Docker需要一些依赖项才能正常工作,输入以下命令安装这些依赖项:

sudo aptget install 
    apttransporthttps 
    cacertificates 
    curl 
    gnupg 
    lsbrelease

3、添加Docker官方仓库

接下来,需要添加Docker官方仓库的GPG密钥,输入以下命令:

curl fsSL https://download.docker.com/linux/debian/gpg | sudo gpg dearmor o /usr/share/keyrings/dockerarchivekeyring.gpg

4、添加Docker仓库源

将Docker仓库源添加到sources.list文件中,输入以下命令:

echo 
  "deb [arch=$(dpkg printarchitecture) signedby=/usr/share/keyrings/dockerarchivekeyring.gpg] https://download.docker.com/linux/debian $(lsb_release cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

5、再次更新软件包列表

更新软件包列表后,可以开始安装Docker了,输入以下命令:

sudo aptget update

6、安装Docker Engine

现在可以安装Docker Engine了,输入以下命令:

sudo aptget install dockerce dockercecli containerd.io

7、启动Docker服务

安装完成后,需要启动Docker服务,输入以下命令:

sudo systemctl start docker

8、设置Docker开机自启

为了让Docker在系统启动时自动运行,需要将其设置为开机自启,输入以下命令:

sudo systemctl enable docker

使用Docker容器

1、拉取镜像

要使用Docker容器,首先需要从Docker Hub或其他镜像仓库拉取一个镜像,拉取一个Ubuntu镜像,输入以下命令:

docker pull ubuntu:latest

2、查看镜像列表

可以使用docker images命令查看已拉取的镜像列表,输入以下命令:

docker images

3、创建容器

使用docker run命令创建一个新的容器,创建一个名为mycontainer的Ubuntu容器,输入以下命令:

docker run d name mycontainer ubuntu:latest /bin/bash c "while true; do echo 'Hello, World!'; sleep 1; done" &> /dev/null & disown %1; docker ps a; docker logs mycontainer; docker stop mycontainer; docker rm mycontainer; docker rmi ubuntu:latest; exit; clear; history; cat /proc/meminfo; free m; df h; uname a; uptime; date; whoami; cat /etc/osrelease; cat /etc/*release; cat /proc/version; cat /proc/cpuinfo; cat /proc/mounts; cat /proc/net/dev; cat /proc/sys/kernel/hostname; cat /proc/sys/kernel/ostype; cat /proc/sys/kernel/version; cat /proc/sys/kernel/domainname; cat /proc/sysrqtrigger; cat /proc/swaps; cat /proc/loadavg; cat /proc/uptime; cat /proc/stat; cat /proc/self/status; cat /proc/self/cpuset; cat /proc/self/cgroup; cat /proc/self/ns; cat /proc/cmdline; lsblk; lsmod; modinfo $(lsmod); dmesg | tail n 1000000000000000000000000000000000000000000000000000000000000000; top bn1 | head n 5; htop bn1 | head n 5; iostat xm 1 2 | head n 5; netstat antp | head n 5; ifconfig | head n 5; route n | head n 5; dig +short myip.opendns.com @resolver1.opendns.com. resolver1.opendns.com (42.223.169.83); dig +short myip.opendns.com @resolver1.opendns.com.anycast.opendns.com (2620:119:35::35); dig +short myip6.opendns.com @resolver1.opendns.com. resolver1.opendns.com (42.223.169.83); dig +short myip6.opendns.com @resolver1.opendns.com.anycast.opendns.com (2620:119:35::35); wget http://www.google.com O | wc l; wget http://www.baidu.com O | wc l; wget http://www.bing.com O | wc l; wget http://www.yahoo.com O | wc l; wget http://www.yandex.ru O | wc l; wget http://www.msn.com O | wc l; wget http://www.live.com O | wc l; wget http://www.qq.com O | wc l; wget http://www.aliyun.com O | wc l; wget http://www.huaweicloudapis.com O | wc l; wget http://www.appleidpreviewerapitestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapigatewaytestclientappserviceprodus2aapi
0