文章目录

  • 下载安装
  • 在 Docker 中使用镜像
  • 运行 Docker 容器
  • Docker运行Nginx
    • 1、获取Nginx镜像
    • 2、运行Nginx容器

下载安装

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

检查 Docker 是否正在运行:

sudo systemctl status docker

类似以下内容,说明该服务处于活动状态并且正在运行:

root@VM-16-5-ubuntu:/home/ubuntu# sudo systemctl status docker
● docker.service - Docker Application Container EngineLoaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)Active: active (running) since Tue 2022-02-08 00:03:36 CST; 10h agoDocs: https://docs.docker.comMain PID: 15585 (dockerd)Tasks: 9CGroup: /system.slice/docker.service└─15585 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

默认情况下,docker命令只能由 root 用户或由 docker 组中的用户运行,docker 组用户是在Docker安装过程中自动创建的。

在 Docker 中使用镜像

Docker 容器(containers)是从 Docker 镜像生成出来的。默认情况下,Docker 从Docker Hub下载这些镜像,Docker 公司在运营这个Docker Hub。

要检查是否可以访问 Docker Hub 和从这个网站下载镜像,请输入:

docker run hello-world

如果你得到以下结果,说明你的机器访问 Docker hub 一切顺畅:

$ docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
0e03bdcc26d7: Pull complete
Digest: sha256:d58e752213a51785838f9eed2b7a498ffa1cb3aa7f946dda11af39286c3db9a9
Status: Downloaded newer image for hello-world:latestHello from Docker!
This message shows that your installation appears to be working correctly.To generate this message, Docker took the following steps:1. The Docker client contacted the Docker daemon.2. The Docker daemon pulled the "hello-world" image from the Docker Hub.

执行此命令时,Docker 首先在本地查找hello-world,如没有,它会从 Docker Hub(默认版本库)下载了该镜像。下载镜像后,Docker 会根据镜像创建一个容器,并执行该容器中的应用程序。

您可以通过将docker命令与search子命令配合使用来搜索 Docker Hub 上可用的镜像。

例如,要搜索 Ubuntu 的镜像,请输入:

docker search ubuntu

此命令会在 Docker Hub 上搜索并返回名称与搜索字符串匹配的所有镜像列表。

执行后显示的结果如下:

NAME                                                      DESCRIPTION                                     STARS               OFFICIAL            AUTOMATED
ubuntu                                                    Ubuntu is a Debian-based Linux operating sys…   11102               [OK]
dorowu/ubuntu-desktop-lxde-vnc                            Docker image to provide HTML5 VNC interface …   443                                     [OK]
rastasheep/ubuntu-sshd                                    Dockerized SSH service, built on top of offi…   245                                     [OK]
consol/ubuntu-xfce-vnc                                    Ubuntu container with "headless" VNC session…   220                                     [OK]
ubuntu-upstart                                            Upstart is an event-based replacement for th…   110                 [OK]
neurodebian                                               NeuroDebian provides neuroscience research s…   68                  [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mysql-5      ubuntu-16-nginx-php-phpmyadmin-mysql-5          50                                      [OK]
ubuntu-debootstrap                                        debootstrap --variant=minbase --components=m…   44                  [OK]
nuagebec/ubuntu                                           Simple always updated Ubuntu docker images w…   24                                      [OK]
i386/ubuntu                                               Ubuntu is a Debian-based Linux operating sys…   21
1and1internet/ubuntu-16-apache-php-5.6                    ubuntu-16-apache-php-5.6                        14                                      [OK]
1and1internet/ubuntu-16-apache-php-7.0                    ubuntu-16-apache-php-7.0                        13                                      [OK]
1and1internet/ubuntu-16-nginx-php-phpmyadmin-mariadb-10   ubuntu-16-nginx-php-phpmyadmin-mariadb-10       11                                      [OK]
1and1internet/ubuntu-16-nginx-php-5.6                     ubuntu-16-nginx-php-5.6                         8                                       [OK]
1and1internet/ubuntu-16-nginx-php-5.6-wordpress-4         ubuntu-16-nginx-php-5.6-wordpress-4             7                                       [OK]
1and1internet/ubuntu-16-apache-php-7.1                    ubuntu-16-apache-php-7.1                        6                                       [OK]
darksheer/ubuntu                                          Base Ubuntu Image -- Updated hourly             5                                       [OK]
1and1internet/ubuntu-16-nginx-php-7.0                     ubuntu-16-nginx-php-7.0                         4                                       [OK]
pivotaldata/ubuntu                                        A quick freshening-up of the base Ubuntu doc…   4
pivotaldata/ubuntu16.04-build                             Ubuntu 16.04 image for GPDB compilation         2
1and1internet/ubuntu-16-sshd                              ubuntu-16-sshd                                  1                                       [OK]
smartentry/ubuntu                                         ubuntu with smartentry                          1                                       [OK]
1and1internet/ubuntu-16-php-7.1                           ubuntu-16-php-7.1                               1                                       [OK]
pivotaldata/ubuntu-gpdb-dev                               Ubuntu images for GPDB development              1
pivotaldata/ubuntu16.04-test                              Ubuntu 16.04 image for GPDB testing             0

“ OFFICIAL” 列(即官方)对应的镜像,就是出自官方的镜像了,大家可放心使用。

接下来,我们可以用pull子命令,将你需要的镜像下载到计算机。

本教程我们使用ubuntu的官方镜像。

docker pull ubuntu

你将看到以下执行结果:

Using default tag: latest
latest: Pulling from library/ubuntu
692c352adcf2: Pull complete
97058a342707: Pull complete
2821b8e766f4: Pull complete
4e643cc37772: Pull complete
Digest: sha256:55cd38b70425947db71112eb5dddfa3aa3e3ce307754a3df2269069d2278ce47
Status: Downloaded newer image for ubuntu:latest
docker.io/library/ubuntu:latest

下载镜像后,可以用run来运行镜像。

从上面这个案例我们可以发现,使用run来执行本地不存在的hello-world镜像时, docker 发现本地没有这个镜像,会直接在 Docker hub 上查找并下载对应的镜像。

要查看已下载到计算机的镜像:

docker images

输出结果如下:

root@VM-16-5-ubuntu:/home/ubuntu# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
ubuntu        latest    54c9d81cbb44   6 days ago     72.8MB
hello-world   latest    feb5d9fea6a5   4 months ago   13.3kB

当镜像执行时,它会生成一个容器,我们在容器中添加所需的软件后,可以把这个容器再次打包成新镜像。

运行 Docker 容器

在上一步的例子中,我们执行了hello-world并学习了如何查看镜像和容器。但其实容器并不仅仅是这样,它可比这有用的多。接下来我们来看看容器能做些什么。

作为示例,让我们用 Ubuntu 最新镜像来运行。使用-i -t 这两个参数,可以让你通过 shell 来管理他们。

docker run -it ubuntu

执行命令后,提示符会变为你正在使用镜像的容器id:

root@7896ef8f403f:/#

Docker运行Nginx

1、获取Nginx镜像

要运行容器,首先需要有相应的镜像,使用下面的命令拉取NGINX镜像:

docker pull nginx

如图所示

2、运行Nginx容器

获取Nginx镜像之后,我们就可以根据镜像来运行容器

docker run --name=nginx -d -p 4030:80 nginx

上面命令的解释如下:

  1. –name:设置容器的名称。
  2. -d:表示在后台运行容器。
  3. -p:指定端口映射。4030是宿主机的端口,80是Nginx容器内部的端口。
  4. nginx:表示根据nginx镜像运行容器。

如图所示

然后在浏览器里面访问:

出现上面的截图,就说明Nginx容器运行成功。

Docker下载安装运行Nginx服务相关推荐

  1. 53.Azure中CentOS的Docker里安装运行SQL Server容器

    大家熟悉SQL Server可以安装在Windows系统上,我也介绍了SQL Server可以安装在LInux上,那么今天我将给大家介绍SQL Server安装在Docker上成为容器快速运行起来 首 ...

  2. Nginx在阿里云的下载安装以及Nginx常见的命令及配置文件

    Nginx在阿里云的下载安装以及Nginx常见的命令及配置文件 首先对于在阿里云如何下载安装nginx,我试了很多的方式都失败了,最终发现这样的方式是可以成功下载并安装的. 下载安装: 第一步:安装编 ...

  3. Anaconda3-2022.10下载安装运行(Win11)

    Anaconda是一个开源的数据科学平台,它将数据科学中的好工具集中在一起.它是一个数据科学栈,包含100多个基于Python.Scala和R的工具包.在它的包管理器conda的帮助下,用户能够使用数 ...

  4. Docker Toolbox下载安装运行镜像

    1.Docker Toolbox下载 这是Docker Toolbox的下载链接,找个最新的下就好了. 阿里云开源镜像站资源目录 2.Docker Toolbox安装 下载之后点击exe文件点击安装, ...

  5. docker下载安装,命令大全

    Docker 官网                        Github Docker 源码 Docker 简介 Docker 是一个开源的应用容器引擎,基于 Go 语言 并遵从 Apache2 ...

  6. Docker Consul 安装及使用服务发现

    更多配置和原理:https://blog.csdn.net/liuzhuchen/article/details/81913562 从2016年起就开始接触Consul,使用的主要目的就是做服务发现, ...

  7. linux docker nginx,CentOS7上Docker简单安装及nginx部署

    安装 如果原来安装过docker,先把原来的删掉,再安装(如果是首次安装docker忽略第一步,直接在第二步看起) 1.1先查看下已经安装了那些docker yum list installed | ...

  8. 虚拟机下载安装、Docker下载安装

    虚拟机 虚拟机使用准备 首先检查自己计算机的虚拟化状态. win10为例,打开任务管理器: 如果虚拟化是已禁用,需要自己上网百度自己的电脑如何开启虚拟化,一般都是在开机时进入BIOS去调试每个品牌或主 ...

  9. iis php mysql 一键安装_LNMP(Nginx服务,MySQL 服务,安装PHP服务 手动安装技术文档)

    文章目录 安装Nginx服务 1.关闭防火墙将nginx所需软件包到/opt目录下 2.安装依赖包 3. 创建运行用户 4.编译安装 5.优化路径 6.添加 Nginx 系统服务 二.安装 MySQL ...

最新文章

  1. 【去广告首选】优酷云-A站-B站-优酷-乐视-搜狐--pptv 接口分享
  2. EasyUI,对treegrid进行编辑
  3. PubMedQA生物医学研究问题解答数据集(2019)下载
  4. AI 研究人员收入超过百万美元!
  5. 反编译代码遇到的问题
  6. Postman发送GET请求带中文
  7. 面向对象14:变长数组Vector、static关键字
  8. logrotate日志转储
  9. java visio_Visio画UML类图、序列图 for Java
  10. rfid sim卡 android,手机专用SIM卡的非接触移动支付技术标准之争:NFC vs RFID
  11. 计算机桌面常用图标,电脑常用软件图标 常用的电脑软件图标
  12. 数学建模大赛准备方法及资源分享
  13. 新手小白学JAVA-显示系统中文件的后缀名
  14. 裁判文书android app逆向
  15. 2022年「博客之星」参赛博主:一个处女座的测试
  16. Ubuntu 18.04 服务器版安装桌面及软件
  17. 完全用Linux编程及其后续
  18. 批处理之批量修改文件扩展名
  19. AI创业有风险,起步需谨慎!创业者从准备到失败~
  20. maven配置中央仓库,阿里云仓库地址

热门文章

  1. 计算机论文的致谢部分写什么,论文的致谢部分怎么写
  2. UI设计中一致性为什么这么重要
  3. python鲜花_【实战案例】90 行Python代码实现一棵鲜花盛开树
  4. 浏览器隐私模式真的可以保证我们的隐私不被透露吗?
  5. 当原图片加载失败时,如何让图片加载上我们默认给的图片
  6. Prometheus配置企业微信报警
  7. 关于Spark Steaming中的Processing Time/Total Delay/Processing Delay
  8. conv1d(): argument ‘padding‘ (position 5) must be tuple of ints, not str 这个错误是怎么回事呀?请各位帮忙看看,万分感谢
  9. 音叉公振频率与双臂质量的计算关系
  10. CommandNotFoundError: No command ‘conda activate‘