Docker筑基篇-上

Posted Fire king

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Docker筑基篇-上相关的知识,希望对你有一定的参考价值。

1.Docker安装心酸历程

step:

1.1.卸载旧的版本

sudo yum remove docker \\
                  docker-client \\
                  docker-client-latest \\
                  docker-common \\
                  docker-latest \\
                  docker-latest-logrotate \\
                  docker-logrotate \\
                  docker-engine

1.2.安装一些docker需要的安装包

yum install -y yum-utils

1.3.设置镜像仓库

yum-config-manager \\
    --add-repo \\
    https://download.docker.com/linux/centos/docker-ce.repo #国外的非常慢
yum-config-manager \\
         --add-repo \\
    http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo #推荐使用阿里云

1.4.安装docker引擎

yum install docker-ce docker-ce-cli containerd.io

1.5.启动docker

systemctl start docker

1.6.hello world

docker run hello-world

1.7.

docker version                 #docker版本信息
docker info                    #docker系统信息,包括镜像和容器数量
docker 命令 --help            #万能命令

1.8.

docker images
REPOSITORY    TAG       IMAGE ID       CREATED         SIZE
hello-world   latest    bf756fb1ae65   12 months ago   13.3kB

执行过程:

login as: root
Last login: Tue Mar 23 17:57:54 2021 from localhost
[root@localhost ~]# sudo yum remove docker \\
>                   docker-client \\
>                   docker-client-latest \\
>                   docker-common \\
>                   docker-latest \\
>                   docker-latest-logrotate \\
>                   docker-logrotate \\
>                   docker-engine
Loaded plugins: fastestmirror, langpacks
No Match for argument: docker
No Match for argument: docker-client
No Match for argument: docker-client-latest
No Match for argument: docker-common
No Match for argument: docker-latest
No Match for argument: docker-latest-logrotate
No Match for argument: docker-logrotate
No Match for argument: docker-engine
No Packages marked for removal
[root@localhost ~]# yum install -y yum-utils
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Resolving Dependencies
--> Running transaction check
---> Package yum-utils.noarch 0:1.1.31-50.el7 will be updated
---> Package yum-utils.noarch 0:1.1.31-54.el7_8 will be an update
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package           Arch           Version                    Repository    Size
================================================================================
Updating:
 yum-utils         noarch         1.1.31-54.el7_8            base         122 k

Transaction Summary
================================================================================
Upgrade  1 Package

Total download size: 122 k
Downloading packages:
No Presto metadata available for base
warning: /var/cache/yum/x86_64/7/base/packages/yum-utils-1.1.31-54.el7_8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID f4a80eb5: NOKEY
Public key for yum-utils-1.1.31-54.el7_8.noarch.rpm is not installed
yum-utils-1.1.31-54.el7_8.noarch.rpm                       | 122 kB   00:00
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Importing GPG key 0xF4A80EB5:
 Userid     : "CentOS-7 Key (CentOS 7 Official Signing Key) <security@centos.org>"
 Fingerprint: 6341 ab27 53d7 8a78 a7c2 7bb1 24c6 a8a7 f4a8 0eb5
 Package    : centos-release-7-6.1810.2.el7.centos.x86_64 (@anaconda)
 From       : /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Updating   : yum-utils-1.1.31-54.el7_8.noarch                             1/2
  Cleanup    : yum-utils-1.1.31-50.el7.noarch                               2/2
  Verifying  : yum-utils-1.1.31-54.el7_8.noarch                             1/2
  Verifying  : yum-utils-1.1.31-50.el7.noarch                               2/2

Updated:
  yum-utils.noarch 0:1.1.31-54.el7_8

Complete!
[root@localhost ~]# yum-config-manager \\
>          --add-repo \\
>     http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
Loaded plugins: fastestmirror, langpacks
adding repo from: http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
grabbing file http://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo to /etc/yum.repos.d/docker-ce.repo
repo saved to /etc/yum.repos.d/docker-ce.repo
[root@localhost ~]# yum install docker-ce docker-ce-cli containerd.io
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: mirrors.aliyun.com
docker-ce-stable                                         | 3.5 kB     00:00
(1/2): docker-ce-stable/7/x86_64/updateinfo                |   55 B   00:00
(2/2): docker-ce-stable/7/x86_64/primary_db                |  58 kB   00:00
Resolving Dependencies
--> Running transaction check
---> Package containerd.io.x86_64 0:1.4.4-3.1.el7 will be installed
--> Processing Dependency: container-selinux >= 2:2.74 for package: containerd.io-1.4.4-3.1.el7.x86_64
---> Package docker-ce.x86_64 3:20.10.5-3.el7 will be installed
--> Processing Dependency: docker-ce-rootless-extras for package: 3:docker-ce-20.10.5-3.el7.x86_64
---> Package docker-ce-cli.x86_64 1:20.10.5-3.el7 will be installed
--> Running transaction check
---> Package container-selinux.noarch 2:2.119.2-1.911c772.el7_8 will be installed
---> Package docker-ce-rootless-extras.x86_64 0:20.10.5-3.el7 will be installed
--> Processing Dependency: fuse-overlayfs >= 0.7 for package: docker-ce-rootless-extras-20.10.5-3.el7.x86_64
--> Processing Dependency: slirp4netns >= 0.4 for package: docker-ce-rootless-extras-20.10.5-3.el7.x86_64
--> Running transaction check
---> Package fuse-overlayfs.x86_64 0:0.7.2-6.el7_8 will be installed
--> Processing Dependency: libfuse3.so.3(FUSE_3.2)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3(FUSE_3.0)(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
--> Processing Dependency: libfuse3.so.3()(64bit) for package: fuse-overlayfs-0.7.2-6.el7_8.x86_64
---> Package slirp4netns.x86_64 0:0.4.3-4.el7_8 will be installed
--> Running transaction check
---> Package fuse3-libs.x86_64 0:3.6.1-4.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

================================================================================
 Package                Arch   Version                   Repository        Size
================================================================================
Installing:
 containerd.io          x86_64 1.4.4-3.1.el7             docker-ce-stable  33 M
 docker-ce              x86_64 3:20.10.5-3.el7           docker-ce-stable  27 M
 docker-ce-cli          x86_64 1:20.10.5-3.el7           docker-ce-stable  33 M
Installing for dependencies:
 container-selinux      noarch 2:2.119.2-1.911c772.el7_8 extras            40 k
 docker-ce-rootless-extras
                        x86_64 20.10.5-3.el7             docker-ce-stable 9.1 M
 fuse-overlayfs         x86_64 0.7.2-6.el7_8             extras            54 k
 fuse3-libs             x86_64 3.6.1-4.el7               extras            82 k
 slirp4netns            x86_64 0.4.3-4.el7_8             extras            81 k

Transaction Summary
================================================================================
Install  3 Packages (+5 Dependent packages)

Total download size: 102 M
Installed size: 424 M
Is this ok [y/d/N]: y
Downloading packages:
(1/8): container-selinux-2.119.2-1.911c772.el7_8.noarch.rp |  40 kB   00:00
warning: /var/cache/yum/x86_64/7/docker-ce-stable/packages/docker-ce-20.10.5-3.el7.x86_64.rpm: Header V4 RSA/SHA512 Signature, key ID 621e9f35: NOKEY
Public key for docker-ce-20.10.5-3.el7.x86_64.rpm is not installed
(2/8): docker-ce-20.10.5-3.el7.x86_64.rpm                  |  27 MB   00:23
(3/8): docker-ce-cli-20.10.5-3.el7.x86_64.rpm              |  33 MB   00:18
(4/8): fuse3-libs-3.6.1-4.el7.x86_64.rpm                   |  82 kB   00:00
(5/8): containerd.io-1.4.4-3.1.el7.x86_64.rpm              |  33 MB   00:42
(6/8): fuse-overlayfs-0.7.2-6.el7_8.x86_64.rpm             |  54 kB   00:01
(7/8): slirp4netns-0.4.3-4.el7_8.x86_64.rpm                |  81 kB   00:02
(8/8): docker-ce-rootless-extras-20.10.5-3.el7.x86_64.rpm  | 9.1 MB   00:04
--------------------------------------------------------------------------------
Total                                              2.2 MB/s | 102 MB  00:45
Retrieving key from https://download.docker.com/linux/centos/gpg
Importing GPG key 0x621E9F35:
 Userid     : "Docker Release (CE rpm) <docker@docker.com>"
 Fingerprint: 060a 61c5 1b55 8a7f 742b 77aa c52f eb6b 621e 9f35
 From       : https://download.docker.com/linux/centos/gpg
Is this ok [y/N]: y
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch           1/8
  Installing : containerd.io-1.4.4-3.1.el7.x86_64                           2/8
  Installing : slirp4netns-0.4.3-4.el7_8.x86_64                             3/8
  Installing : fuse3-libs-3.6.1-4.el7.x86_64                                4/8
  Installing : fuse-overlayfs-0.7.2-6.el7_8.x86_64                          5/8
  Installing : 1:docker-ce-cli-20.10.5-3.el7.x86_64                         6/8
  Installing : docker-ce-rootless-extras-20.10.5-3.el7.x86_64               7/8
  Installing : 3:docker-ce-20.10.5-3.el7.x86_64                             8/8
  Verifying  : 1:docker-ce-cli-20.10.5-3.el7.x86_64                         1/8
  Verifying  : fuse3-libs-3.6.1-4.el7.x86_64                                2/8
  Verifying  : fuse-overlayfs-0.7.2-6.el7_8.x86_64                          3/8
  Verifying  : slirp4netns-0.4.3-4.el7_8.x86_64                             4/8
  Verifying  : 2:container-selinux-2.119.2-1.911c772.el7_8.noarch           5/8
  Verifying  : 3:docker-ce-20.10.5-3.el7.x86_64                             6/8
  Verifying  : docker-ce-rootless-extras-20.10.5-3.el7.x86_64               7/8
  Verifying  : containerd.io-1.4.4-3.1.el7.x86_64                           8/8

Installed:
  containerd.io.x86_64 0:1.4.4-3.1.el7     docker-ce.x86_64 3:20.10.5-3.el7
  docker-ce-cli.x86_64 1:20.10.5-3.el7

Dependency Installed:
  container-selinux.noarch 2:2.119.2-1.911c772.el7_8
  docker-ce-rootless-extras.x86_64 0:20.10.5-3.el7
  fuse-overlayfs.x86_64 0:0.7.2-6.el7_8
  fuse3-libs.x86_64 0:3.6.1-4.el7
  slirp4netns.x86_64 0:0.4.3-4.el7_8

Complete!
[root@localhost ~]# systemctl start docker
[root@localhost ~]# docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
b8dfde127a29: Pull complete
Digest: sha256:308866a43596e83578c7dfa15e27a73011bdd402185a84c5cd7f32a88b501a24
Status: Downloaded newer image for hello-world:latest

Hello 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.
    (amd64)
 3. The Docker daemon created a new container from that image which runs the
    executable that produces the output you are currently reading.
 4. The Docker daemon streamed that output to the Docker client, which sent it
    to your terminal.

To try something more ambitious, you can run an Ubuntu container with:
 $ docker run -it ubuntu bash

Share images, automate workflows, and more with a free Docker ID:
 https://hub.docker.com/

For more examples and ideas, visit:
 https://docs.docker.com/get-started/
 
[root@localhost ~]# docker version
Client: Docker Engine - Community
 Version:           20.10.5
 API version:       1.41
 Go version:        go1.13.15
 Git commit:        55c4c88
 Built:             Tue Mar  2 20:33:55 2021
 OS/Arch:           linux/amd64
 Context:           default
 Experimental:      true

Server: Docker Engine - Community
 Engine:
  Version:          20.10.5
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.13.15
  Git commit:       363e9a8
  Built:            Tue Mar  2 20:32:17 2021
  OS/Arch:          linux/amd64
  Experimental:     false
 containerd:
  Version:          1.4.4
  GitCommit:        05f951a3781f4f2c1911b05e61c160e9c30eaa8e
 runc:
  Version:          1.0.0-rc93
  GitCommit:        12644e614e25b05da6fd08a38ffa0cfe1903fdec
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    d1165f221234   2 weeks ago   13.3kB
[root@localhost ~]#

2.配置阿里镜像加速器

[root@localhost ~]# sudo mkdir -p /etc/docker
[root@localhost ~]# sudo tee /etc/docker/daemon.json <<-'EOF'
> {
>   "registry-mirrors": ["https://xdswrn5u.mirror.aliyuncs.com"]
> }
> EOF
{
  "registry-mirrors": ["https://xdswrn5u.mirror.aliyuncs.com"]
}
[root@localhost ~]# sudo systemctl daemon-reload
[root@localhost ~]# sudo systemctl restart docker

3.docker常用命令:

3.1.帮助命令:

docker -version #显示docker版本信息
docker info #显示docker的系统信息,包括镜像和容器数量
docker 命令 --help #帮助命令

docker官网帮助文档:
文档地址
左侧栏有一对命令可供学习
在这里插入图片描述

3.2.镜像命令:

3.2.1.普通命令

[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   2 weeks ago    13.3kB
tomcat        9.0       040bdb29ab37   2 months ago   649MB
tomcat        latest    040bdb29ab37   2 months ago   649MB
nginx         latest    f6d0b4767a6c   2 months ago   133MB

#参数解释
REPOSITORY  镜像的仓库源
TAG         镜像的标签
IMAGE ID    镜像的id
CREATED     镜像的创建时间
SIZE        镜像的大小

#可选项:
-a , --all      #列出所有镜像
-q , --quiet    #只显示镜像id

[root@localhost ~]# docker images -a
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   2 weeks ago    13.3kB
tomcat        9.0       040bdb29ab37   2 months ago   649MB
tomcat        latest    040bdb29ab37   2 months ago   649MB
nginx         latest    f6d0b4767a6c   2 months ago   133MB

[root@localhost ~]# docker images -q
d1165f221234
040bdb29ab37
040bdb29ab37
f6d0b4767a6c

[root@localhost ~]# docker images -aq
d1165f221234
040bdb29ab37
040bdb29ab37
f6d0b4767a6c

[root@localhost ~]# docker images hello-world -q
d1165f221234


3.2.2.docker search 搜索镜像:

[root@localhost ~]# docker mysql
docker: 'mysql' is not a docker command.
See 'docker --help'
[root@localhost ~]# docker search mysql
NAME                              DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql                             MySQL is a widely used, open-source relation…   10656     [OK]
mariadb                           MariaDB Server is a high performing open sou…   3997      [OK]
mysql/mysql-server                Optimized MySQL Server Docker images. Create…   779                  [OK]
percona                           Percona Server is a fork of the MySQL relati…   528       [OK]
centos/mysql-57-centos7           MySQL 5.7 SQL database server                   87

#可选项:
-f, --filter filter   Filter output based on conditions provided
      --format string   Pretty-print search using a Go template
      --limit int       Max number of search results (default 25)
      --no-trunc        Don't truncate output
      
--filter=STARS=3000 #搜索出来的镜像就是收藏大于3000的

[root@localhost ~]# docker search mysql --filter=STARS=3000
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql     MySQL is a widely used, open-source relation…   10656     [OK]
mariadb   MariaDB Server is a high performing open sou…   3997      [OK]

[root@localhost ~]# docker search mysql --filter=STARS=5000
NAME      DESCRIPTION                                     STARS     OFFICIAL   AUTOMATED
mysql     MySQL is a widely used, open-source relation…   10656     [OK]

3.2.3.docker pull 下载镜像:

分层下载:相同的层共用,不再重复下载,极大节省内存资源,显示为Already exists

#下载镜像 docker pull镜像名[:tag]
root@localhost ~]# docker pull nginx
Using default tag: latest #不写tag(版本,默认就是latest(最新的)
latest: Pulling from library/nginx
a076a628af6f: Pull complete  #分层下载,docker的核心就是联合文件系统
0732ab25fa22: Pull complete
d7f36f6fe38f: Pull complete
f72584a26f32: Pull complete
7125e4df9063: Pull complete
Digest: sha256:10b8cc432d56da8b61b070f4c7d2543a9ed17c2b23010b43af434fd40e2ca4aa
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest #真实地址

#以下两个命令是等价的
docker pull nginx
docker pull docker.io/library/nginx:latest

#指定版本下载,并且一定是dockerhub上面有的,如下图
docker pull nginx 1.18

在这里插入图片描述

3.2.3.docker rmi 删除镜像:

听说容器id写前三位就可以了

docker rmi -f 容器id #删除指定容器
docker rmi -f 容器id 容器id 容器id #删除多个容器
docker rmi -f ${docker images -aq} #删除全部容器

3.3.容器命令:

注意:有了镜像才能创建容器,相当于类跟实例的关系。

3.3.1创建一个centos来测试:

[root@localhost ~]# docker pull centos
Using default tag: latest
latest: Pulling from library/centos
7a0437f04f83: Pull complete
Digest: sha256:5528e8b1b1719d34604c87e11dcd1c0a20bedf46e83b5632cdeac91b8c04efc1
Status: Downloaded newer image for centos:latest
docker.io/library/centos:latest

3.3.2新建容器并启动:

docker run [可选参数] image

#参数说明
--name="Name" 容器名字,tomcat01,tomcat02用来区分容器
-d            后台方式运行
-it           使用交互方式运行,进入容器查看内容
-P            使用容器端口 -P 8080:8080
	-P ip:主机端口:容器端口
	-P 主机端口:容器端口(常用)
	-P 容器端口
-p            随机指定端口

#测试,启动并进入容器
[root@localhost ~]# docker run -it centos /bin/bash
[root@c6e6c5dc6f24 /]# ls #查看容器内部的centos,基础版本,很多命令都是不完善的
bin  etc   lib    lost+found  mnt  proc  run   srv  tmp  var
dev  home  lib64  media       opt  root  sbin  sys  usr

#从容器退回主机
[root@c6e6c5dc6f24 /]# exit
exit
[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg

3.3.3.列出所有运行的容器:

#docker ps 命令
		#列出当前正在运行的容器
-a		#列出当前正在运行的容器+历史运行过的容器
-n=?		#列出最近创建的容器
-q      #只显示容器的编号
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED        STATUS        PORTS                    NAMES
aec63ded193c   tomcat    "catalina.sh run"        17 hours ago   Up 17 hours   0.0.0.0:3355->8080/tcp   tomcat01
3cb23d454a26   nginx     "/docker-entrypoint.…"   18 hours ago   Up 18 hours   0.0.0.0:3344->80/tcp     nginx_1
[root@localhost ~]# docker ps -a
CONTAINER ID   IMAGE         COMMAND                  CREATED         STATUS                     PORTS                    NAMES
c6e6c5dc6f24   centos        "/bin/bash"              5 minutes ago   Exited (0) 2 minutes ago                            vibrant_bassi
aec63ded193c   tomcat        "catalina.sh run"        17 hours ago    Up 17 hours                0.0.0.0:3355->8080/tcp   tomcat01
3cb23d454a26   nginx         "/docker-entrypoint.…"   18 hours ago    Up 18 hours                0.0.0.0:3344->80/tcp     nginx_1
53c6c1d7b511   hello-world   "/hello"                 26 hours ago    Exited (0) 26 hours ago                             priceless_sanderson
[root@localhost ~]# docker ps -a -n=1
CONTAINER ID   IMAGE     COMMAND       CREATED         STATUS                     PORTS     NAMES
c6e6c5dc6f24   centos    "/bin/bash"   8 minutes ago   Exited (0) 6 minutes ago             vibrant_bassi

3.3.4.退出容器:

exit  #直接停止容器并退出
ctrl+p+q #容器不停止退出

部署nginx
demo:

# 搜索nginx
docker search nginx
# 下载nginx镜像
docker pull nginx
# 查看镜像
docker images
# 后台,重命名,外部端口和内部端口映射 启动
docker run -d --name nginx_1 -p 3344:80 nginx
# 测试是否成功
curl localhost:3344
# 进入nginx容器内部
docker exec -it nginx_1 /bin/bash
        # 查看nginx位置
        whereis nginx
        # 进入nginx
        cd /etc/nginx
        ls
        # 退出容器,不停止应用
        ctrl+p+q

3.3.4.删除容器:

docker rm 容器id  #删除指定容器,但不能删除正在运行的容器,如果要强制删除 rm -f
docker rm -f ${docker ps -aq} #删除所有容器
docker ps -a -q|xargs docker rm #删除所有容器

3.3.4.启动和停止容器操作:

docker start 容器id    #启动容器
docker restart 容器id  #重启容器
docker stop 容器id     #停止正在运行的容器
docker kill 容器id     #强制停止正在运行的容器
[root@localhost ~]# docker pull nginx
Using default tag: latest
latest: Pulling from library/nginx
a076a628af6f: Pull complete
0732ab25fa22: Pull complete
d7f36f6fe38f: Pull complete
f72584a26f32: Pull complete
7125e4df9063: Pull complete
Digest: sha256:10b8cc432d56da8b61b070f4c7d2543a9ed17c2b23010b43af434fd40e2ca4aa
Status: Downloaded newer image for nginx:latest
docker.io/library/nginx:latest
[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   2 weeks ago    13.3kB
nginx         latest    f6d0b4767a6c   2 months ago   133MB
[root@localhost ~]# docker run -d --name nginx_1 -p 3344:80 nginx
3cb23d454a2624268fab7970442a168f50cd4b362a999c387c0957571b813898
[root@localhost ~]# curl localhost:3344
<!DOCTYPE html>
<html>
<head>
<title>Welcome to nginx!</title>
<style>
    body {
        width: 35em;
        margin: 0 auto;
        font-family: Tahoma, Verdana, Arial, sans-serif;
    }
</style>
</head>
<body>
<h1>Welcome to nginx!</h1>
<p>If you see this page, the nginx web server is successfully installed and
working. Further configuration is required.</p>

<p>For online documentation and support please refer to
<a href="http://nginx.org/">nginx.org</a>.<br/>
Commercial support is available at
<a href="http://nginx.com/">nginx.com</a>.</p>

<p><em>Thank you for using nginx.</em></p>
</body>
</html>
   0.0.0.0:3344->80/tcp   nginx_1
[root@localhost ~]# docker exec -it nginx_1 /bin/bash
root@3cb23d454a26:/# whereis nginx
nginx: /usr/sbin/nginx /usr/lib/nginx /etc/nginx /usr/share/nginx
root@3cb23d454a26:/# cd /etc/nginx
root@3cb23d454a26:/etc/nginx# ls
conf.d          koi-utf  mime.types  nginx.conf   uwsgi_params
fastcgi_params  koi-win  modules     scgi_params  win-utf
root@3cb23d454a26:/etc/nginx# read escape sequence
[root@localhost ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                  CREATED          STATUS          PORTS                  NAMES
3cb23d454a26   nginx     "/docker-entrypoint.…"   20 minutes ago   Up 20 minutes   0.0.0.0:3344->80/tcp   nginx_1

部署tomcat9.0
此命令用完即删容器,镜像还在

[root@localhost ~]# docker run -it --rm tomcat:9.0

[root@localhost ~]# docker images
REPOSITORY    TAG       IMAGE ID       CREATED        SIZE
hello-world   latest    d1165f221234   2 weeks ago    13.3kB
tomcat        9.0       040bdb29ab37   2 months ago   649MB
nginx         latest    f6d0b4767a6c   2 months ago   133MB

自行拉取运行
注意:访问tomcat主页可能会出现404,通过阿里镜像拉取的tomcat是被阉割掉的(只保证最小运行条件),

以上是关于Docker筑基篇-上的主要内容,如果未能解决你的问题,请参考以下文章

HTML筑基篇

蓝桥杯-筑基篇贪心

Django用websocket实现聊天室之筑基篇

一文详解:中信银行java笔试题库

一文详解:中信银行java笔试题库

一文详解:中信银行java笔试题库