如何在Ubuntu中安装Docker和运行 Docker容器

Docker是一种开源且流行的操作系统级虚拟化(俗称“容器化”)技术,主要在Linux和Windows上运行。 Docker使用容器可以更轻松地创建,部署和运行应用程序。

使用容器,开发人员(和系统管理员)可以使用运行应用程序所需的一切来打包应用程序 - 代码,运行时,库,环境变量和配置文件,并将它们作为一个包发送出去。 是的,真是太好了!

在本文中,我们将向您展示如何安装Docker CE(Community Edition),在Ubuntu发行版上创建和运行Docker容器。

在Ubuntu中安装Docker CE(Community Edition)

1.要安装Docker CE,首先,您需要使用以下命令从系统中删除旧版本的Docker,称为docker,docker.io或docker-engine。

linuxidc@linuxidc:~/www.linuxidc.com/Linux公社 -$ sudo apt-get remove docker docker-engine docker.io containerd runc

如何在Ubuntu中安装Docker和运行 Docker容器

2.接下来,您需要设置Docker存储库以使用以下命令从存储库安装和更新Docker。

linuxidc@linuxidc:~/www.linuxidc.com/Linux公社 -$ sudo apt-get update

linuxidc@linuxidc:~/www.linuxidc.com/Linux公社 -$ curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
OK
linuxidc@linuxidc:~/www.linuxidc.com/Linux公社 -$ sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"

如何在Ubuntu中安装Docker和运行 Docker容器

3.使用以下命令更新apt软件包索引并安装最新版本的Docker CE。

linuxidc@linuxidc:~/www.linuxidc.com/Linux公社 -$ sudo apt-get update

linuxidc@linuxidc:~/www.linuxidc.com/Linux公社 -$ sudo apt-get install docker-ce docker-ce-cli containerd.io

如何在Ubuntu中安装Docker和运行 Docker容器

4.成功安装Docker CE软件包后,该服务应自动启动并自动启用以在系统引导时启动,您可以使用以下命令检查其状态。

linuxidc@linuxidc:~/www.linuxidc.com/Linux公社 -$ sudo systemctl status docker
[sudo] linuxidc 的密码:
● docker.service - Docker Application Container Engine
  Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: e
  Active: active (running) since Thu 2019-03-07 20:23:49 CST; 16min ago
    Docs: https://docs.docker.com
 Main PID: 15355 (dockerd)
    Tasks: 9
  CGroup: /system.slice/docker.service
          └─15355 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/contai

如何在Ubuntu中安装Docker和运行 Docker容器

5.最后,通过运行hello-world映像验证Docker CE是否已正确安装。

linuxidc@linuxidc:~/www.linuxidc.com/Linux公社 -$ sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
1b930d010525: Pull complete
Digest: sha256:2557e3c07ed1e38f26e389462d03ed943586f744621577a99efb77324b0fe535
Status: Downloaded newer image for hello-world:latest

Hello from Docker!
This message shows that your installation appears to be working correctly.

如何在Ubuntu中安装Docker和运行 Docker容器

在Ubuntu中学习基本的Docker命令

6.要获取有关Docker的信息,请运行以下命令。

linuxidc@linuxidc:~/www.linuxidc.com/Linux公社 -$ sudo docker info
Containers: 1
 Running: 0
 Paused: 0
 Stopped: 1
Images: 1
Server Version: 18.09.3
Storage Driver: overlay2
 Backing Filesystem: extfs
 Supports d_type: true
 Native Overlay Diff: true
Logging Driver: json-file
Cgroup Driver: cgroupfs
Plugins:
 Volume: local
 Network: bridge host macvlan null overlay
 Log: awslogs fluentd gcplogs gelf journald json-file local logentries splunk syslog
Swarm: inactive
Runtimes: runc
Default Runtime: runc
Init Binary: docker-init
containerd version: e6b3f5632f50dbc4e9cb6288d911bf4f5e95b18e
runc version: 6635b4f0c6af3810594d2770f662f34ddc15b40d
init version: fec3683
Security Options:
 apparmor
 seccomp
  Profile: default
Kernel Version: 4.18.0-15-generic
Operating System: Ubuntu 18.04.2 LTS
OSType: linux
Architecture: x86_64
CPUs: 1
Total Memory: 2.847GiB
Name: linuxidc
ID: GOFC:PMVS:TLNX:K2UZ:4L5U:L46W:BQ5C:FVUE:7P76:XVP2:SAEZ:RAET
Docker Root Dir: /var/lib/docker
Debug Mode (client): false
Debug Mode (server): false
Registry: https://index.docker.io/v1/
Labels:
Experimental: false
Insecure Registries:
 127.0.0.0/8
Live Restore Enabled: false
Product License: Community Engine

WARNING: No swap limit support
linuxidc@linuxidc:~/www.linuxidc.com/Linux公社 -$

如何在Ubuntu中安装Docker和运行 Docker容器

7.要获取有关Docker版本的信息,请运行以下命令。

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/12162.html