微服务day02

教学文档:

黑马教学文档

Docker

Docker的安装 

镜像和容器

命令解读

常见命令

案例

查看DockerHub,拉取Nginx镜像,创建并运行容器

搜索Nginx镜像:在 www.hub.docker.com 网站进行查询

拉取镜像:

docker pull nginx

查看本地镜像列表:

docker images

将拉取到本地的镜像进行打包,保存为文件

[root@server02 ~]# docker save --help//查询docker save的命令的用法Usage:  docker save [OPTIONS] IMAGE [IMAGE...]Save one or more images to a tar archive (streamed to STDOUT by default)Aliases:docker image save, docker save//由此可知 该命令有 -o 表示设置 镜像的存储文件nginx.tar
Options:-o, --output string   Write to a file, instead of STDOUT
[root@server02 ~]# ^C
[root@server02 ~]# docker save -o nginx.tar nginx
[root@server02 ~]# ls
anaconda-ks.cfg  dist.zip  hello            install.sh                       nginx.tar        RDM-用户需求说明书.doc  公共  视频  文档  音乐
Desktop          download  hello-nginx.zip  jdk-17.0.8_linux-x64_bin.tar.gz  original-ks.cfg  xp-install.log          模板  图片  下载  桌面
[root@server02 ~]#

删除本地镜像

[root@server02 ~]# docker rmi nginx
Untagged: nginx:latest
Untagged: nginx@sha256:fad8e1cd52e24bce7b72cd7cb674a2efad671647b917055f5bd8a1f7ac9b1af8
Deleted: sha256:3f8a4339aadda5897b744682f5f774dc69991a81af8d715d37a616bb4c99edf5
Deleted: sha256:bb528503f6f01b70cd8de94372e1e3196fad3b28da2f69b105e95934263b0487
Deleted: sha256:410204d28a96d436e31842a740ad0c827f845d22e06f3b1ff19c3b22706c3ed4
Deleted: sha256:2ec5c0a4cb57c0af7c16ceda0b0a87a54f01f027ed33836a5669ca266cafe97a
[root@server02 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                   CREATED        STATUS          PORTS                                                  NAMES
d81b6044c59d   mysql     "docker-entrypoint.s…"   18 hours ago   Up 17 minutes   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
[root@server02 ~]#

提取本地镜像文件

[root@server02 ~]# docker load --helpUsage:  docker load [OPTIONS]Load an image from a tar archive or STDINAliases:docker image load, docker loadOptions:-i, --input string   Read from tar archive file, instead of STDIN-q 表示是否显示提去细节-q, --quiet          Suppress the load output
[root@server02 ~]#提去本地文件,只需要指定文件名即可[root@server02 ~]# docker load -i nginx.tar
2ec5c0a4cb57: Loading layer [==================================================>]  58.43MB/58.43MB
73e2bd445514: Loading layer [==================================================>]  53.76MB/53.76MB
a103d141fc98: Loading layer [==================================================>]  3.584kB/3.584kB
Loaded image: nginx:latest
[root@server02 ~]# docker ps
CONTAINER ID   IMAGE     COMMAND                   CREATED        STATUS          PORTS                                                  NAMES
d81b6044c59d   mysql     "docker-entrypoint.s…"   19 hours ago   Up 23 minutes   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
[root@server02 ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
mysql        latest    be960704dfac   2 weeks ago   602MB
nginx        latest    3f8a4339aadd   6 years ago   108MB
[root@server02 ~]#

创建并运行NGINX容器


d81b6044c59d   mysql     "docker-entrypoint.s…"   20 hours ago   Up 2 hours   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
[root@server02 ~]# docker run -d --name nginx -p 90:80 nginx
cd42761dd7ead46aa2c0a9147f5fe0c1f9d200a253cfeee584d6b03d6c66a30b

查看容器

# 第5步,查看运行中容器
docker ps
# 也可以加格式化方式访问,格式会更加清爽
docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Ports}}\t{{.Status}}\t{{.Names}}"

关闭进程

[root@server02 ~]# docker stop nginx
nginx
[root@server02 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED              STATUS                     PORTS                                                  NAMES
cd42761dd7ea   nginx     "nginx -g 'daemon of…"   About a minute ago   Exited (0) 4 seconds ago                                                          nginx
d81b6044c59d   mysql     "docker-entrypoint.s…"   20 hours ago         Up 2 hours                 0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
[root@server02 ~]#

启动容器

[root@server02 ~]# docker start nginx
nginx
[root@server02 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED         STATUS        PORTS                                                  NAMES
cd42761dd7ea   nginx     "nginx -g 'daemon of…"   2 minutes ago   Up 1 second   0.0.0.0:90->80/tcp, :::90->80/tcp                      nginx
d81b6044c59d   mysql     "docker-entrypoint.s…"   20 hours ago    Up 2 hours    0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
[root@server02 ~]#

查看容器详细信息

# 第11步,查看容器详细信息
docker inspect nginx

进入容器

# 第12步,进入容器,查看容器内目录
-it 表示进入命令行交互
bash 为指定交互 语言
docker exec -it nginx bash
# 或者,可以进入MySQL
docker exec -it mysql mysql -uroot -p

删除容器

# 第13步,删除容器
docker rm nginx
# 发现无法删除,因为容器运行中,强制删除容器
docker rm -f nginx[root@server02 ~]# docker rm nginx
Error response from daemon: cannot remove container "/nginx": container is running: stop the container before removing or force remove
[root@server02 ~]# docker rm -f nginx
nginx
[root@server02 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED        STATUS       PORTS                                                  NAMES
d81b6044c59d   mysql     "docker-entrypoint.s…"   20 hours ago   Up 2 hours   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
[root@server02 ~]#

命令别名

设置别名:root目录下 .bashrc文件进行设置

# .bashrc# User specific aliases and functionsalias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'# Source global definitions
if [ -f /etc/bashrc ]; then. /etc/bashrc
fi
~
~
~
~

修改文件,

# 修改/root/.bashrc文件
vi /root/.bashrc
内容如下:
# .bashrc# User specific aliases and functionsalias rm='rm -i'
alias cp='cp -i'
alias mv='mv -i'
alias dps='docker ps --format "table {{.ID}}\t{{.Image}}\t{{.Ports}}\t{{.Status}}\t{{.Names}}"'
alias dis='docker images'# Source global definitions
if [ -f /etc/bashrc ]; then. /etc/bashrc
fi

执行命令使别名生效

source /root/.bashrc

实例:

[root@server02 ~]# vim .bashrc
[root@server02 ~]# source /root/.bashrc
[root@server02 ~]# dps
CONTAINER ID   IMAGE     PORTS                                                  STATUS       NAMES
d81b6044c59d   mysql     0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   Up 3 hours   mysql
[root@server02 ~]# dis
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
mysql        latest    be960704dfac   2 weeks ago   602MB
nginx        latest    3f8a4339aadd   6 years ago   108MB
[root@server02 ~]#

数据卷

案例:利用Nginx容器部署静态资源

  1. 进入容器内部:
[root@server02 ~]# docker exec -it nginx bash
  1. 通过在DockerHub中查找可知Nginx的静态资源存放在 ‘/usr/share/nginx/html/index.html’文件中,由于容器没有提供非必要的依赖,所以没有修改文件的命令(vim)无法修改,由此引入数据卷。
[root@server02 ~]# docker images
REPOSITORY   TAG       IMAGE ID       CREATED       SIZE
mysql        latest    be960704dfac   2 weeks ago   602MB
nginx        latest    3f8a4339aadd   6 years ago   108MB
[root@server02 ~]# docker run -d --name nginx -p 90:80 nginx
4081207a48ee7f1338b2136166b72f1adb424f5482193ab2a52e9c747acd481d
[root@server02 ~]# docker exec -it nginx bash
root@4081207a48ee:/# ls
bin  boot  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
root@4081207a48ee:/# cd /usr/share/nginx/html
root@4081207a48ee:/usr/share/nginx/html# ls
50x.html  index.html
root@4081207a48ee:/usr/share/nginx/html# vi index.html
bash: vi: command not found
root@4081207a48ee:/usr/share/nginx/html#

        

 

删除原有的Nginx的容器[root@server02 ~]# docker rm -f nginx
nginx创建新的容器并创建数据卷,设置数据卷名称为html,根据容器中的存储位置指定[root@server02 ~]# docker run -d --name nginx -p 90:80 -v html:/usr/share/nginx/html nginx
c0f9d2c91c9dd88f2e767bda76453f0f836585c71b4dc129886850bc7a2fe130
[root@server02 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED         STATUS         PORTS                                                  NAMES
c0f9d2c91c9d   nginx     "nginx -g 'daemon of…"   8 seconds ago   Up 6 seconds   0.0.0.0:90->80/tcp, :::90->80/tcp                      nginx
d81b6044c59d   mysql     "docker-entrypoint.s…"   22 hours ago    Up 4 hours     0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
[root@server02 ~]# docker volume psUsage:  docker volume COMMANDManage volumesCommands:create      Create a volumeinspect     Display detailed information on one or more volumesls          List volumesprune       Remove unused local volumesrm          Remove one or more volumesupdate      Update a volume (cluster volumes only)Run 'docker volume COMMAND --help' for more information on a command.显示所有的数据卷[root@server02 ~]# docker volume ls
DRIVER    VOLUME NAME
local     bb415299e39a1c7425861ee4add16668301e28c419cde8e35f5c436a69f228a4
local     html展示数据卷的详情信息,其中有宿主机中文件的位置
[root@server02 ~]# docker volume inspect html[{"CreatedAt": "2024-11-02T19:57:10+08:00","Driver": "local","Labels": null,"Mountpoint": "/var/lib/docker/volumes/html/_data","Name": "html","Options": null,"Scope": "local"}
]
[root@server02 ~]# ^C进入宿主机的文件位置
[root@server02 ~]# cd /var/lib/docker/volumes/html/_data
[root@server02 _data]# ls
50x.html  index.html
[root@server02 _data]# cat index.html容器中的数据
<!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>
[root@server02 _data]#

案例2:Mysql数据挂载

查看Mysql容器的详细挂载:

# 1.查看MySQL容器详细信息
docker inspect mysql
# 关注其中.Config.Volumes部分和.Mounts部分

[root@server02 _data]# docker inspect mysql
[{"Id": "d81b6044c59d6dc6bdfd89ee6308b24c8b15bc62a67e58eb58a51471663fdb11","Created": "2024-11-01T13:40:38.673884478Z","Path": "docker-entrypoint.sh","Args": ["mysqld"],"State": {"Status": "running","Running": true,"Paused": false,"Restarting": false,"OOMKilled": false,"Dead": false,"Pid": 1988,"ExitCode": 0,"Error": "","StartedAt": "2024-11-02T12:43:18.287204296Z","FinishedAt": "2024-11-02T12:42:46.40149356Z"},"Image": "sha256:be960704dfac8744a2e2df80c90087551a998ac008916b9d1423d7b0c5ee33ea","ResolvConfPath": "/var/lib/docker/containers/d81b6044c59d6dc6bdfd89ee6308b24c8b15bc62a67e58eb58a51471663fdb11/resolv.conf","HostnamePath": "/var/lib/docker/containers/d81b6044c59d6dc6bdfd89ee6308b24c8b15bc62a67e58eb58a51471663fdb11/hostname","HostsPath": "/var/lib/docker/containers/d81b6044c59d6dc6bdfd89ee6308b24c8b15bc62a67e58eb58a51471663fdb11/hosts","LogPath": "/var/lib/docker/containers/d81b6044c59d6dc6bdfd89ee6308b24c8b15bc62a67e58eb58a51471663fdb11/d81b6044c59d6dc6bdfd89ee6308b24c8b15bc62a67e58eb58a51471663fdb11-json.log","Name": "/mysql","RestartCount": 0,"Driver": "overlay2","Platform": "linux","MountLabel": "","ProcessLabel": "","AppArmorProfile": "","ExecIDs": null,"HostConfig": {"Binds": null,"ContainerIDFile": "","LogConfig": {"Type": "json-file","Config": {}},"NetworkMode": "bridge","PortBindings": {"3306/tcp": [{"HostIp": "","HostPort": "3306"}]},"RestartPolicy": {"Name": "always","MaximumRetryCount": 0},"AutoRemove": false,"VolumeDriver": "","VolumesFrom": null,"ConsoleSize": [40,80],"CapAdd": null,"CapDrop": null,"CgroupnsMode": "host","Dns": [],"DnsOptions": [],"DnsSearch": [],"ExtraHosts": null,"GroupAdd": null,"IpcMode": "private","Cgroup": "","Links": null,"OomScoreAdj": 0,"PidMode": "","Privileged": false,"PublishAllPorts": false,"ReadonlyRootfs": false,"SecurityOpt": null,"UTSMode": "","UsernsMode": "","ShmSize": 67108864,"Runtime": "runc","Isolation": "","CpuShares": 0,"Memory": 0,"NanoCpus": 0,"CgroupParent": "","BlkioWeight": 0,"BlkioWeightDevice": [],"BlkioDeviceReadBps": [],"BlkioDeviceWriteBps": [],"BlkioDeviceReadIOps": [],"BlkioDeviceWriteIOps": [],"CpuPeriod": 0,"CpuQuota": 0,"CpuRealtimePeriod": 0,"CpuRealtimeRuntime": 0,"CpusetCpus": "","CpusetMems": "","Devices": [],"DeviceCgroupRules": null,"DeviceRequests": null,"MemoryReservation": 0,"MemorySwap": 0,"MemorySwappiness": null,"OomKillDisable": false,"PidsLimit": null,"Ulimits": [],"CpuCount": 0,"CpuPercent": 0,"IOMaximumIOps": 0,"IOMaximumBandwidth": 0,"MaskedPaths": ["/proc/asound","/proc/acpi","/proc/kcore","/proc/keys","/proc/latency_stats","/proc/timer_list","/proc/timer_stats","/proc/sched_debug","/proc/scsi","/sys/firmware","/sys/devices/virtual/powercap"],"ReadonlyPaths": ["/proc/bus","/proc/fs","/proc/irq","/proc/sys","/proc/sysrq-trigger"]},"GraphDriver": {"Data": {"LowerDir": "/var/lib/docker/overlay2/3cf60d95239daad11fb5ab3980198891888748066b529da9d663da08d9dbcf7f-init/diff:/var/lib/docker/overlay2/2e296e4d0a879890f34b553a9c3f59fa842faf33f37cdd692113dd269ec1adef/diff:/var/lib/docker/overlay2/2c31d039bb31ffb6ac4da3b76ee29ac8ee1b7b918c7be92595d9a76c63cbf0e0/diff:/var/lib/docker/overlay2/7a1225bf1b17ea29ec4595d8fb4b2b41e3a65f9f7ea532181bca4c259cc8df8d/diff:/var/lib/docker/overlay2/9c123ce4975933c8fdd1d01976c202afd48c4f7425e97ee29b363984c26898bb/diff:/var/lib/docker/overlay2/2e56e6f4d9796d51c25133bdf1f652254678c379a584edc4dd4340b1af1b6a36/diff:/var/lib/docker/overlay2/e8e715b5664a9962b35f9bbf33f62d814d7de58a29c11da00a2c9b41c9eb51da/diff:/var/lib/docker/overlay2/36f7c8ada99b2753cb094209970fa771f5d104b1e1c04a3234fea11260f5055c/diff:/var/lib/docker/overlay2/c4ddb63b3f27ffc789739b457035c23e6c7cd762e2a58da055a0f8ccb6c2e7f7/diff:/var/lib/docker/overlay2/66bc1e7635002279b4e9a3167244ac63845ac61f0bbf1e69ce7b2acfc2f45ee0/diff:/var/lib/docker/overlay2/fa8051a8bb240be1431a320cc952996f212a9a0282a8d2e31e15ad2817a6bc29/diff","MergedDir": "/var/lib/docker/overlay2/3cf60d95239daad11fb5ab3980198891888748066b529da9d663da08d9dbcf7f/merged","UpperDir": "/var/lib/docker/overlay2/3cf60d95239daad11fb5ab3980198891888748066b529da9d663da08d9dbcf7f/diff","WorkDir": "/var/lib/docker/overlay2/3cf60d95239daad11fb5ab3980198891888748066b529da9d663da08d9dbcf7f/work"},"Name": "overlay2"},"Mounts": [{"Type": "volume","Name": "bb415299e39a1c7425861ee4add16668301e28c419cde8e35f5c436a69f228a4","Source": "/var/lib/docker/volumes/bb415299e39a1c7425861ee4add16668301e28c419cde8e35f5c436a69f228a4/_data","Destination": "/var/lib/mysql","Driver": "local","Mode": "","RW": true,"Propagation": ""}],"Config": {"Hostname": "d81b6044c59d","Domainname": "","User": "","AttachStdin": false,"AttachStdout": false,"AttachStderr": false,"ExposedPorts": {"3306/tcp": {},"33060/tcp": {}},"Tty": false,"OpenStdin": false,"StdinOnce": false,"Env": ["TZ=Asia/Shanghai","MYSQL_ROOT_PASSWORD=123","PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin","GOSU_VERSION=1.17","MYSQL_MAJOR=innovation","MYSQL_VERSION=9.1.0-1.el9","MYSQL_SHELL_VERSION=9.1.0-1.el9"],"Cmd": ["mysqld"],"Image": "mysql","Volumes": {"/var/lib/mysql": {}},"WorkingDir": "/","Entrypoint": ["docker-entrypoint.sh"],"OnBuild": null,"Labels": {}},"NetworkSettings": {"Bridge": "","SandboxID": "99e3029f08cd8edcaf9feac159a4a80a295b2751a97e3ab7f8ccd098ba3edfcd","SandboxKey": "/var/run/docker/netns/99e3029f08cd","Ports": {"3306/tcp": [{"HostIp": "0.0.0.0","HostPort": "3306"},{"HostIp": "::","HostPort": "3306"}],"33060/tcp": null},"HairpinMode": false,"LinkLocalIPv6Address": "","LinkLocalIPv6PrefixLen": 0,"SecondaryIPAddresses": null,"SecondaryIPv6Addresses": null,"EndpointID": "bb696f63baf3dfc2a498766837c478b3e535bd0d07414b66db75af55f57438bb","Gateway": "172.17.0.1","GlobalIPv6Address": "","GlobalIPv6PrefixLen": 0,"IPAddress": "172.17.0.2","IPPrefixLen": 16,"IPv6Gateway": "","MacAddress": "02:42:ac:11:00:02","Networks": {"bridge": {"IPAMConfig": null,"Links": null,"Aliases": null,"MacAddress": "02:42:ac:11:00:02","NetworkID": "2479e9c603f8bd3f6a4815a430cfdc37081daa5fd57ad1a8225a92e309c7dd90","EndpointID": "bb696f63baf3dfc2a498766837c478b3e535bd0d07414b66db75af55f57438bb","Gateway": "172.17.0.1","IPAddress": "172.17.0.2","IPPrefixLen": 16,"IPv6Gateway": "","GlobalIPv6Address": "","GlobalIPv6PrefixLen": 0,"DriverOpts": null,"DNSNames": null}}}}
]
[root@server02 _data]#

Mounts部分为挂载信息,在创建容器时就自动创建挂载用来存储数据库中的数据。使用的是匿名卷,

可以发现,其中有几个关键属性:

  • Name:数据卷名称。由于定义容器未设置容器名,这里的就是匿名卷自动生成的名字,一串hash值。

  • Source:宿主机目录

  • Destination : 容器内的目录

上述配置是将容器内的/var/lib/mysql这个目录,与数据卷bb415299e39a1c7425861ee4add16668301e28c419cde8e35f5c436a69f228a4挂载。于是在宿主机中就有了/var/lib/docker/volumes/bb415299e39a1c7425861ee4add16668301e28c419cde8e35f5c436a69f228a4/_data这个目录。这就是匿名数据卷对应的目录,其使用方式与普通数据卷没有差别。

可以发现,数据卷的目录结构较深,如果我们去操作数据卷目录会不太方便。在很多情况下,我们会直接将容器目录与宿主机指定目录挂载。挂载语法与数据卷类似:

# 挂载本地目录
-v 本地目录:容器内目录
# 挂载本地文件
-v 本地文件:容器内文件

注意:本地目录或文件必须以 /./开头,如果直接以名字开头,会被识别为数据卷名而非本地目录名。

-v mysql:/var/lib/mysql # 会被识别为一个数据卷叫mysql,运行时会自动创建这个数据卷
-v ./mysql:/var/lib/mysql # 会被识别为当前目录下的mysql目录,运行时如果不存在会创建目录

创建要挂载的文件夹,并将提供的资料中的文件拉人文件夹中,包括配置文件和初始化数据库文件。

[root@server02 _data]# ^C
[root@server02 _data]# cd /root
[root@server02 ~]# mkdir mysql
[root@server02 ~]# cd mysql
[root@server02 mysql]# mkdir data
[root@server02 mysql]# mkdir init
[root@server02 mysql]# mkdir conf
[root@server02 mysql]# ls
conf  data  init
[root@server02 mysql]#

删除已存在的数据库容器:

[root@server02 mysql]# docker rm -f mysql
mysql
[root@server02 mysql]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED       STATUS          PORTS                               NAMES
c0f9d2c91c9d   nginx     "nginx -g 'daemon of…"   2 hours ago   Up 34 minutes   0.0.0.0:90->80/tcp, :::90->80/tcp   nginx
[root@server02 mysql]#

修改新的数据库容器的创建语句:

docker run -d \--name mysql \-p 3306:3306 \-e TZ=Asia/Shanghai \-e MYSQL_ROOT_PASSWORD=123 \-v ./mysql/data:/var/lib/mysql \-v ./mysql/conf:/etc/mysql/conf.d \-v ./mysql/init:/docker-entrypoint-initdb.d \mysql
# 4.查看root目录,可以发现~/mysql/data目录已经自动创建好了
ls -l mysql
# 结果:
总用量 4
drwxr-xr-x. 2 root    root   20 5月  19 15:11 conf
drwxr-xr-x. 7 polkitd root 4096 5月  19 15:11 data
drwxr-xr-x. 2 root    root   23 5月  19 15:11 init# 查看data目录,会发现里面有大量数据库数据,说明数据库完成了初始化
ls -l data# 5.查看MySQL容器内数据
# 5.1.进入MySQL
docker exec -it mysql mysql -uroot -p123
# 5.2.查看编码表
show variables like "%char%";
# 5.3.结果,发现编码是utf8mb4没有问题
+--------------------------+--------------------------------+
| Variable_name            | Value                          |
+--------------------------+--------------------------------+
| character_set_client     | utf8mb4                        |
| character_set_connection | utf8mb4                        |
| character_set_database   | utf8mb4                        |
| character_set_filesystem | binary                         |
| character_set_results    | utf8mb4                        |
| character_set_server     | utf8mb4                        |
| character_set_system     | utf8mb3                        |
| character_sets_dir       | /usr/share/mysql-8.0/charsets/ |
+--------------------------+--------------------------------+# 6.查看数据
# 6.1.查看数据库
show databases;
# 结果,hmall是黑马商城数据库
+--------------------+
| Database           |
+--------------------+
| hmall              |
| information_schema |
| mysql              |
| performance_schema |
| sys                |
+--------------------+
5 rows in set (0.00 sec)
# 6.2.切换到hmall数据库
use hmall;
# 6.3.查看表
show tables;
# 结果:
+-----------------+
| Tables_in_hmall |
+-----------------+
| address         |
| cart            |
| item            |
| order           |
| order_detail    |
| order_logistics |
| pay_order       |
| user            |
+-----------------+
# 6.4.查看address表数据
+----+---------+----------+--------+----------+-------------+---------------+-----------+------------+-------+
| id | user_id | province | city   | town     | mobile      | street        | contact   | is_default | notes |
+----+---------+----------+--------+----------+-------------+---------------+-----------+------------+-------+
| 59 |       1 | 北京     | 北京   | 朝阳区    | 13900112222 | 金燕龙办公楼   | 李佳诚    | 0          | NULL  |
| 60 |       1 | 北京     | 北京   | 朝阳区    | 13700221122 | 修正大厦       | 李佳红    | 0          | NULL  |
| 61 |       1 | 上海     | 上海   | 浦东新区  | 13301212233 | 航头镇航头路   | 李佳星    | 1          | NULL  |
| 63 |       1 | 广东     | 佛山   | 永春      | 13301212233 | 永春武馆       | 李晓龙    | 0          | NULL  |
+----+---------+----------+--------+----------+-------------+---------------+-----------+------------+-------+
4 rows in set (0.00 sec)

自定义镜像

例如,要基于Ubuntu镜像来构建一个Java应用,其Dockerfile内容如下:

# 指定基础镜像
FROM ubuntu:16.04
# 配置环境变量,JDK的安装目录、容器内时区
ENV JAVA_DIR=/usr/local
ENV TZ=Asia/Shanghai
# 拷贝jdk和java项目的包
COPY ./jdk8.tar.gz $JAVA_DIR/
COPY ./docker-demo.jar /tmp/app.jar
# 设定时区
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 安装JDK
RUN cd $JAVA_DIR \&& tar -xf ./jdk8.tar.gz \&& mv ./jdk1.8.0_144 ./java8
# 配置环境变量
ENV JAVA_HOME=$JAVA_DIR/java8
ENV PATH=$PATH:$JAVA_HOME/bin
# 指定项目监听的端口
EXPOSE 8080
# 入口,java项目的启动命令
ENTRYPOINT ["java", "-jar", "/app.jar"]

就有人提供了基础的系统加JDK环境,我们在此基础上制作java镜像,就可以省去JDK的配置了:

# 基础镜像
FROM openjdk:11.0-jre-buster
# 设定时区
ENV TZ=Asia/Shanghai
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
# 拷贝jar包
COPY docker-demo.jar /app.jar
# 入口
ENTRYPOINT ["java", "-jar", "/app.jar"]

由于要下载JDK到本地所以先上传JDK到本地镜像


[root@server02 ~]# docker load -i jdk.tar
2c7e7ab2260a: Loading layer [==================================================>]  119.3MB/119.3MB
9ad2165feb02: Loading layer [==================================================>]  17.18MB/17.18MB
92903c3857f8: Loading layer [==================================================>]  17.87MB/17.87MB
1736ab871b32: Loading layer [==================================================>]  12.18MB/12.18MB
6f8e4cb95a88: Loading layer [==================================================>]  3.584kB/3.584kB
41080a0c646f: Loading layer [==================================================>]  141.8MB/141.8MB
Loaded image: openjdk:11.0-jre-buster
[root@server02 ~]# docker ps -
"docker ps" accepts no arguments.
See 'docker ps --help'.Usage:  docker ps [OPTIONS]List containers
[root@server02 ~]# docker ps -A
unknown shorthand flag: 'A' in -A
See 'docker ps --help'.
[root@server02 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED             STATUS             PORTS                                                  NAMES
dbf730d0ef60   mysql     "docker-entrypoint.s…"   About an hour ago   Up About an hour   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
c0f9d2c91c9d   nginx     "nginx -g 'daemon of…"   3 hours ago         Up 2 hours         0.0.0.0:90->80/tcp, :::90->80/tcp                      nginx
[root@server02 ~]# docker images
REPOSITORY   TAG               IMAGE ID       CREATED       SIZE
mysql        latest            be960704dfac   2 weeks ago   602MB
openjdk      11.0-jre-buster   57925f2e4cff   2 years ago   301MB
nginx        latest            3f8a4339aadd   6 years ago   108MB
[root@server02 ~]# cd /root/demo
[root@server02 demo]# docker build -t docker-demo:1.0 .
[+] Building 1.0s (8/8) FINISHED                                                                                                               docker:default=> [internal] load build definition from Dockerfile                                                                                                     0.0s=> => transferring dockerfile: 299B                                                                                                                     0.0s=> [internal] load metadata for docker.io/library/openjdk:11.0-jre-buster                                                                               0.0s=> [internal] load .dockerignore                                                                                                                        0.0s=> => transferring context: 2B                                                                                                                          0.0s=> [1/3] FROM docker.io/library/openjdk:11.0-jre-buster                                                                                                 0.1s=> [internal] load build context                                                                                                                        0.2s=> => transferring context: 17.70MB                                                                                                                     0.2s=> [2/3] RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone                                             0.6s=> [3/3] COPY docker-demo.jar /app.jar                                                                                                                  0.1s=> exporting to image                                                                                                                                   0.1s=> => exporting layers                                                                                                                                  0.1s=> => writing image sha256:9e95eddcf939bc4f47db257b48be435c1ef4fbe7f954155bb7ffd38c54ecb3f5                                                             0.0s=> => naming to docker.io/library/docker-demo:1.0                                                                                                       0.0s
[root@server02 demo]# docker images
REPOSITORY    TAG               IMAGE ID       CREATED         SIZE
docker-demo   1.0               9e95eddcf939   5 seconds ago   319MB
mysql         latest            be960704dfac   2 weeks ago     602MB
openjdk       11.0-jre-buster   57925f2e4cff   2 years ago     301MB
nginx         latest            3f8a4339aadd   6 years ago     108MB
[root@server02 demo]# docker run -d --name dd -p 8080:8080 docker-demo:1.0
a8fd9609526f1f185148cd5e37bb795d06a100e4660ba57a500cbb206d9d849b
[root@server02 demo]# docker ps -a
CONTAINER ID   IMAGE             COMMAND                   CREATED             STATUS             PORTS                                                  NAMES
a8fd9609526f   docker-demo:1.0   "java -jar /app.jar"      54 seconds ago      Up 52 seconds      0.0.0.0:8080->8080/tcp, :::8080->8080/tcp              dd
dbf730d0ef60   mysql             "docker-entrypoint.s…"   About an hour ago   Up About an hour   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
c0f9d2c91c9d   nginx             "nginx -g 'daemon of…"   3 hours ago         Up 2 hours         0.0.0.0:90->80/tcp, :::90->80/tcp                      nginx
[root@server02 demo]#

网络


删除网络
[root@server02 demo]# docker network rm hmall
hmall
新增
[root@server02 demo]# docker network create wmmczk
462fcfdc6cb2467df985c1eee7c2ca355713321ca05646a4376ec73c8ed71c93显示网络详情
[root@server02 demo]# docker network ls
NETWORK ID     NAME      DRIVER    SCOPE
2479e9c603f8   bridge    bridge    local
18a3f1a81ca7   host      host      local
f3b8297a3f91   none      null      local
462fcfdc6cb2   wmmczk    bridge    local将Mysql加入网络,并起别名db
[root@server02 demo]# docker network connect wmmczk mysql --alias db将dd加入网络
[root@server02 demo]# docker network connect wmmczk dd
[root@server02 demo]# docker exec -it dd bash从dd访问nysql 的别名db
root@a8fd9609526f:/# ping db
PING db (172.19.0.2) 56(84) bytes of data.
64 bytes from mysql.wmmczk (172.19.0.2): icmp_seq=1 ttl=64 time=0.152 ms
64 bytes from mysql.wmmczk (172.19.0.2): icmp_seq=2 ttl=64 time=0.151 ms
^C
--- db ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 3ms
rtt min/avg/max/mdev = 0.073/0.125/0.152/0.038 ms
root@a8fd9609526f:/# ping mysql
PING mysql (172.19.0.2) 56(84) bytes of data.
64 bytes from mysql.wmmczk (172.19.0.2): icmp_seq=1 ttl=64 time=0.258 ms
64 bytes from mysql.wmmczk (172.19.0.2): icmp_seq=2 ttl=64 time=0.098 ms
64 bytes from mysql.wmmczk (172.19.0.2): icmp_seq=3 ttl=64 time=0.072 ms
^C
--- mysql ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 4ms
rtt min/avg/max/mdev = 0.072/0.142/0.258/0.083 ms
root@a8fd9609526f:/#

创建容器时加入 --network 【容器名称】 就可直接加入网络,但是不加入默认网络。

项目部署

后端项目

[root@server02 demo]# cd /root
[root@server02 ~]# docker build -t hmall .
[+] Building 2.3s (8/8) FINISHED                                                                                                               docker:default=> [internal] load build definition from Dockerfile                                                                                                     0.0s=> => transferring dockerfile: 298B                                                                                                                     0.0s=> [internal] load metadata for docker.io/library/openjdk:11.0-jre-buster                                                                               0.0s=> [internal] load .dockerignore                                                                                                                        0.0s=> => transferring context: 2B                                                                                                                          0.0s=> [1/3] FROM docker.io/library/openjdk:11.0-jre-buster                                                                                                 0.0s=> [internal] load build context                                                                                                                        0.7s=> => transferring context: 68.24MB                                                                                                                     0.7s=> CACHED [2/3] RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo Asia/Shanghai > /etc/timezone                                      0.0s=> [3/3] COPY hm-service.jar /app.jar                                                                                                                   1.2s=> exporting to image                                                                                                                                   0.3s=> => exporting layers                                                                                                                                  0.3s=> => writing image sha256:97c798b4ad66621ffe0c767374828880c0a4b1fc060804c4b6bba53511f9bf24                                                             0.0s=> => naming to docker.io/library/hmall                                                                                                                 0.0s
[root@server02 ~]# dis
REPOSITORY    TAG               IMAGE ID       CREATED          SIZE
hmall         latest            97c798b4ad66   5 seconds ago    370MB
docker-demo   1.0               9e95eddcf939   38 minutes ago   319MB
mysql         latest            be960704dfac   2 weeks ago      602MB
openjdk       11.0-jre-buster   57925f2e4cff   2 years ago      301MB
nginx         latest            3f8a4339aadd   6 years ago      108MB
[root@server02 ~]# docker rm -f dd
dd
[root@server02 ~]# docker run -d --name hm -p 8080:8080 --network wmmczk hmall
8de6cc8dcaf73d9452794482fb43327a617a7f7d1b4174baf03143bc1424f0f4
[root@server02 ~]# docker logs -f hm.   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::               (v2.7.12)23:13:45:771  INFO 1 --- [           main] com.hmall.HMallApplication               : Starting HMallApplication v1.0.0 using Java 11.0.13 on 8de6cc8dcaf7 with PID 1 (/app.jar started by root in /)
23:13:45:778 DEBUG 1 --- [           main] com.hmall.HMallApplication               : Running with Spring Boot v2.7.12, Spring v5.3.27
23:13:45:780  INFO 1 --- [           main] com.hmall.HMallApplication               : The following 1 profile is active: "dev"
23:13:48:750  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Multiple Spring Data modules found, entering strict repository configuration mode
23:13:48:761  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Redis repositories in DEFAULT mode.
23:13:48:873  INFO 1 --- [           main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 30 ms. Found 0 Redis repository interfaces.
23:13:51:096  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
23:13:51:130  INFO 1 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
23:13:51:131  INFO 1 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.75]
23:13:51:355  INFO 1 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
23:13:51:355  INFO 1 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 5400 ms_ _   |_  _ _|_. ___ _ |    _
| | |\/|_)(_| | |_\  |_)||_|_\/               |3.4.3
23:13:57:392  INFO 1 --- [           main] pertySourcedRequestMappingHandlerMapping : Mapped URL path [/v2/api-docs] onto method [springfox.documentation.swagger2.web.Swagger2ControllerWebMvc#getDocumentation(String, HttpServletRequest)]
23:13:59:106  INFO 1 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
23:13:59:108  INFO 1 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Documentation plugins bootstrapped
23:13:59:116  INFO 1 --- [           main] d.s.w.p.DocumentationPluginsBootstrapper : Found 1 custom documentation plugin(s)
23:13:59:356  INFO 1 --- [           main] s.d.s.w.s.ApiListingReferenceScanner     : Scanning for api listing references
23:14:00:473  INFO 1 --- [           main] com.hmall.HMallApplication               : Started HMallApplication in 16.316 seconds (JVM running for 17.706)

好了,我们已经熟悉了Docker的基本用法,接下来可以尝试部署项目了。

在课前资料中已经提供了一个黑马商城项目给大家,如图:

项目说明:

  • hmall:商城的后端代码

  • hmall-portal:商城用户端的前端代码

  • hmall-admin:商城管理端的前端代码

部署的容器及端口说明:

项目

容器名

端口

备注

hmall

hmall

8080

黑马商城后端API入口

hmall-portal

nginx

18080

黑马商城用户端入口

hmall-admin

18081

黑马商城管理端入口

mysql

mysql

3306

数据库

在正式部署前,我们先删除之前的nginx、dd两个容器:

 

docker rm -f nginx dd

mysql容器中已经准备好了商城的数据,所以就不再删除了。

3.1.部署Java项目

hmall项目是一个maven聚合项目,使用IDEA打开hmall项目,查看项目结构如图:

我们要部署的就是其中的hm-service,其中的配置文件采用了多环境的方式:

其中的application-dev.yaml是部署到开发环境的配置,application-local.yaml是本地运行时的配置。

查看application.yaml,你会发现其中的JDBC地址并未写死,而是读取变量:

这两个变量在application-dev.yamlapplication-local.yaml中并不相同:

在dev开发环境(也就是Docker部署时)采用了mysql作为地址,刚好是我们的mysql容器名,只要两者在一个网络,就一定能互相访问。

我们将项目打包:

结果:

hm-service目录下的Dockerfilehm-service/target目录下的hm-service.jar一起上传到虚拟机的root目录:

部署项目:

 

# 1.构建项目镜像,不指定tag,则默认为latest docker build -t hmall . # 2.查看镜像 docker images # 结果 REPOSITORY TAG IMAGE ID CREATED SIZE hmall latest 0bb07b2c34b9 43 seconds ago 362MB docker-demo 1.0 49743484da68 24 hours ago 327MB nginx latest 605c77e624dd 16 months ago 141MB mysql latest 3218b38490ce 17 months ago 516MB # 3.创建并运行容器,并通过--network将其加入hmall网络,这样才能通过容器名访问mysql docker run -d --name hmall --network hmall -p 8080:8080 hmall

测试,通过浏览器访问:http://你的虚拟机地址:8080/search/list

前端项目

删除原有的Nginx容器

[root@server02 ~]# docker rm -f nginx
nginx
[root@server02 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED        STATUS                      PORTS     NAMES
8de6cc8dcaf7   hmall     "java -jar /app.jar"      11 hours ago   Exited (143) 11 hours ago             hm
dbf730d0ef60   mysql     "docker-entrypoint.s…"   13 hours ago   Exited (0) 11 hours ago               mysql
[root@server02 ~]#

创建新Nginx容器并进行挂载和加入网络

修改配置文件(即后端容器的名字使前端可以访问后端):

worker_processes  1;events {worker_connections  1024;
}http {include       mime.types;default_type  application/json;sendfile        on;keepalive_timeout  65;server {listen       18080;# 指定前端项目所在的位置location / {root /usr/share/nginx/html/hmall-portal;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}location /api {rewrite /api/(.*)  /$1 break;proxy_pass http://hm:8080;}}server {listen       18081;# 指定前端项目所在的位置location / {root /usr/share/nginx/html/hmall-admin;}error_page   500 502 503 504  /50x.html;location = /50x.html {root   html;}location /api {rewrite /api/(.*)  /$1 break;proxy_pass http://hm:8080;}}
}

然后创建nginx容器并完成两个挂载:

  • /root/nginx/nginx.conf挂载到/etc/nginx/nginx.conf

  • /root/nginx/html挂载到/usr/share/nginx/html

由于需要让nginx同时代理hmall-portal和hmall-admin两套前端资源,因此我们需要暴露两个端口:

  • 18080:对应hmall-portal

  • 18081:对应hmall-admin

命令如下:

docker run -d \--name nginx \-p 18080:18080 \-p 18081:18081 \-v /root/nginx/html:/usr/share/nginx/html \-v /root/nginx/nginx.conf:/etc/nginx/nginx.conf \--network wmmczk\nginx

[root@server02 ~]# docker rm -f nginx
nginx
[root@server02 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED        STATUS                      PORTS     NAMES
8de6cc8dcaf7   hmall     "java -jar /app.jar"      11 hours ago   Exited (143) 11 hours ago             hm
dbf730d0ef60   mysql     "docker-entrypoint.s…"   13 hours ago   Exited (0) 11 hours ago               mysql
[root@server02 ~]# ^C
[root@server02 ~]# docker run -d \
>   --name nginx \
>   -p 18080:18080 \
>   -p 18081:18081 \
>   -v /root/nginx/html:/usr/share/nginx/html \
>   -v /root/nginx/nginx.conf:/etc/nginx/nginx.conf \
>   --network wmmczk\
>   nginx
c1330ae115775b962cf7582805e9feb010ea5b322fcfc3d9aea2a1fa7035eeaf
[root@server02 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED         STATUS                      PORTS     NAMES
c1330ae11577   nginx     "nginx -g 'daemon of…"   6 seconds ago   Exited (1) 4 seconds ago              nginx
8de6cc8dcaf7   hmall     "java -jar /app.jar"      11 hours ago    Exited (143) 11 hours ago             hm
dbf730d0ef60   mysql     "docker-entrypoint.s…"   13 hours ago    Exited (0) 11 hours ago               mysql
[root@server02 ~]# docker start nginx
nginx
[root@server02 ~]# docker start hm
hm
[root@server02 ~]# docker start mysql
mysql
[root@server02 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED              STATUS                      PORTS                                                  NAMES
c1330ae11577   nginx     "nginx -g 'daemon of…"   About a minute ago   Exited (1) 59 seconds ago                                                          nginx
8de6cc8dcaf7   hmall     "java -jar /app.jar"      11 hours ago         Up 46 seconds               0.0.0.0:8080->8080/tcp, :::8080->8080/tcp              hm
dbf730d0ef60   mysql     "docker-entrypoint.s…"   13 hours ago         Up 40 seconds               0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp   mysql
[root@server02 ~]# docker start nginx
nginx
[root@server02 ~]# docker ps -a
CONTAINER ID   IMAGE     COMMAND                   CREATED              STATUS              PORTS                                                                           NAMES
c1330ae11577   nginx     "nginx -g 'daemon of…"   About a minute ago   Up 5 seconds        80/tcp, 0.0.0.0:18080-18081->18080-18081/tcp, :::18080-18081->18080-18081/tcp   nginx
8de6cc8dcaf7   hmall     "java -jar /app.jar"      11 hours ago         Up About a minute   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp                                       hm
dbf730d0ef60   mysql     "docker-entrypoint.s…"   13 hours ago         Up About a minute   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp                            mysql
[root@server02 ~]#

DockerCompose

docker run 参数

docker compose 指令

说明

--name

container_name

容器名称

-p

ports

端口映射

-e

environment

环境变量

-v

volumes

数据卷配置

--network

networks

网络

配置文件:

version: "3.8"services:mysql:image: mysqlcontainer_name: mysqlports:- "3306:3306"environment:TZ: Asia/ShanghaiMYSQL_ROOT_PASSWORD: 123volumes:- "./mysql/conf:/etc/mysql/conf.d"- "./mysql/data:/var/lib/mysql"- "./mysql/init:/docker-entrypoint-initdb.d"networks:- hm-nethmall:build: context: .dockerfile: Dockerfilecontainer_name: hmallports:- "8080:8080"networks:- hm-netdepends_on:- mysqlnginx:image: nginxcontainer_name: nginxports:- "18080:18080"- "18081:18081"volumes:- "./nginx/nginx.conf:/etc/nginx/nginx.conf"- "./nginx/html:/usr/share/nginx/html"depends_on:- hmallnetworks:- hm-net
networks:hm-net:name: hmall

[root@server02 ~]# docker rm -f hm nginx mysql
hm
nginx
mysql
[root@server02 ~]# docker images
REPOSITORY    TAG               IMAGE ID       CREATED        SIZE
hmall         latest            97c798b4ad66   12 hours ago   370MB
docker-demo   1.0               9e95eddcf939   12 hours ago   319MB
mysql         latest            be960704dfac   2 weeks ago    602MB
openjdk       11.0-jre-buster   57925f2e4cff   2 years ago    301MB
nginx         latest            3f8a4339aadd   6 years ago    108MB
[root@server02 ~]# docker rmi hmall docker-demo
Untagged: hmall:latest
Deleted: sha256:97c798b4ad66621ffe0c767374828880c0a4b1fc060804c4b6bba53511f9bf24
Error response from daemon: No such image: docker-demo:latest
[root@server02 ~]# docker compose up -d
WARN[0000] /root/docker-compose.yml: `version` is obsolete
[+] Building 0.1s (8/8) FINISHED                                 docker:default=> [hmall internal] load build definition from Dockerfile                 0.0s=> => transferring dockerfile: 298B                                       0.0s=> [hmall internal] load metadata for docker.io/library/openjdk:11.0-jre  0.0s=> [hmall internal] load .dockerignore                                    0.0s=> => transferring context: 2B                                            0.0s=> [hmall internal] load build context                                    0.0s=> => transferring context: 38B                                           0.0s=> [hmall 1/3] FROM docker.io/library/openjdk:11.0-jre-buster             0.0s=> CACHED [hmall 2/3] RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc  0.0s=> CACHED [hmall 3/3] COPY hm-service.jar /app.jar                        0.0s=> [hmall] exporting to image                                             0.0s=> => exporting layers                                                    0.0s=> => writing image sha256:3e78751a9f66a7824c8dd9a65bc7efa11c9e8def1e7be  0.0s=> => naming to docker.io/library/root-hmall                              0.0s
[+] Running 4/4✔ Network hmall    Created                                                0.1s✔ Container mysql  Started                                                0.5s✔ Container hmall  Started                                                0.9s✔ Container nginx  Started                                                1.7s
[root@server02 ~]# docker compose images
WARN[0000] /root/docker-compose.yml: `version` is obsolete
CONTAINER           REPOSITORY          TAG                 IMAGE ID            SIZE
hmall               root-hmall          latest              3e78751a9f66        370MB
mysql               mysql               latest              be960704dfac        602MB
nginx               nginx               latest              3f8a4339aadd        108MB
[root@server02 ~]# docker compose ps
WARN[0000] /root/docker-compose.yml: `version` is obsolete
NAME      IMAGE        COMMAND                   SERVICE   CREATED         STATUS         PORTS
hmall     root-hmall   "java -jar /app.jar"      hmall     2 minutes ago   Up 2 minutes   0.0.0.0:8080->8080/tcp, :::8080->8080/tcp
mysql     mysql        "docker-entrypoint.s…"   mysql     2 minutes ago   Up 2 minutes   0.0.0.0:3306->3306/tcp, :::3306->3306/tcp, 33060/tcp
nginx     nginx        "nginx -g 'daemon of…"   nginx     2 minutes ago   Up 2 minutes   80/tcp, 0.0.0.0:18080-18081->18080-18081/tcp, :::18080-18081->18080-18081/tcp
[root@server02 ~]#

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.xdnf.cn/news/6168.html

如若内容造成侵权/违法违规/事实不符,请联系一条长河网进行投诉反馈,一经查实,立即删除!

相关文章

MySQL 安装与配置

MySQL 安装与配置 MySQL 安装 MySQL 一般分为社区版和商业版&#xff0c;我们使用的是社区版&#xff08;因为免费&#xff09;。MySQL 安装的教程在网上有很多&#xff0c;此处就不再进行进行赘述&#xff0c;这里推荐两篇文章&#xff1a;如何在 Windows11 中安装 MySQL 8.…

ISUP协议视频平台EasyCVR大华设备视频平台高并发情况下FLV协议流无法播放的原因排查

随着视频监控技术的发展和应用领域的扩大&#xff0c;大中型项目对视频监控系统的需求日益增长&#xff0c;特别是在智慧城市、公共安全、交通管理等领域。这些项目通常涉及跨区域、大规模的视频监控和管理&#xff0c;要求视频监控系统具备高兼容性、高稳定性和高扩展性。ISUP…

Linux学习笔记之vim入门

基本介绍 Linux系统会内置vi文本编辑器&#xff0c;vim具有程序编辑的能力&#xff0c;可看做是vi的增强版本&#xff0c;可以主动以字体颜色辨别语法的正确性&#xff0c;方便程序设计。代码补全、编译以及错误跳转等方便编程的功能特别丰富&#xff0c;在程序员中被广泛使用…

C# 实现读取Excel文件并设置单元格计算公式再保存

背景&#xff1a;需求需要读取数据导出成Excel文件&#xff0c;并且其中有一列需要赋值为公式&#xff0c;用于用户自己修改数据自动计算 导出Excel&#xff0c;我用到开源包MiniExcel Gitee地址MiniExcel源码介绍&#xff0c;功能说明 Nuget安装 搜索MiniExcel 导出代码如下&a…

数学建模启发式算法篇(一)---遗传算法

文章目录 1.引言2.生物学基础2.1适应度2.2染色体&#xff0c;基因 3.算法介绍3.1算法流程3.2编码和解码3.3轮盘赌选择3.4交叉和变异3.5初始参数的设置 4.实际应用-matlab4.1观察图像4.2初始参数说明4.3init初始化4.4二进制转换为十进制4.5选择,交叉过程4.6情况说明4.7代码 1.引…

qt QTreeWidget详解

1、概述 QTreeWidget 是 Qt 框架中的一个类&#xff0c;用于以树形结构展示数据。它基于 QTreeView 并提供了更高级别的接口&#xff0c;使得添加、删除和管理树形结构中的项变得更加简单。QTreeWidget 支持多级嵌套&#xff0c;每个项&#xff08;QTreeWidgetItem&#xff09…

关于离散概率模型的一些介绍

离散概率模型是概率论中的一类重要模型&#xff0c;专门用于描述随机变量取离散值的情况。这类模型在许多领域都有广泛的应用&#xff0c;比如统计学、机器学习、数据挖掘等。在这篇文章中就将介绍离散概率模型有关的东西&#xff0c;具体包括&#xff1a;马尔科夫链、部件与系…

docker镜像仓库常用命令

docker镜像仓库常用命令 docker logindocker logoutdocker pulldocker pushdocker searchdocker imagesdocker image inspectdocker tagdocker rmidocker image prunedocker savedocker loaddocker history docker login 语法: docker login [options] [server] 功能&#xff…

设备树编译报错cell 0 is not a phandle reference

问题一 编译设备树时报错&#xff1a; Warning (clocks_property): /pl0619030000:clocks: cell 0 is not a phandle reference 设备树是qemu执行dump生成的&#xff0c;然后执行反编译得到dts&#xff0c;警告处的源码为&#xff1a; 警告大概意思是时钟的参数应该是一个ph…

jmeter脚本-请求体设置变量and请求体太长的处理

目录 1、查询接口 1.1 准备组织列表的TXT文件&#xff0c;如下&#xff1a; 1.2 添加 CSV数据文件设置 &#xff0c;如下&#xff1a; 1.3 接口请求体设置变量&#xff0c;如下&#xff1a; 2、创建接口 2.1 见1.1 2.2 见1.2 2.3 准备创建接口的请求体TXT文件&#xff…

MySQL 数据库之表操作

1. 创建表 CREATE TABLE table_name ( field1 datatype, field2 datatype, field3 datatype ) [character set 字符集 collate 校验规则 engine 存储引擎];field 表示列名datatype 表示列的类型character set 字符集&#xff0c;如果没有指定字符集&#xff0c;则以所在数据库…

Python数据分析案例62——基于MAGU-LSTM的时间序列预测(记忆增强门控单元)

案例背景 时间序列lstm系列预测在学术界发论文都被做烂了&#xff0c;现在有一个新的MAGU-LSTM层的代码&#xff0c;并且效果还可以&#xff0c;非常少见我觉得还比较创新&#xff0c;然后我就分享一下它的代码演示一下&#xff0c;并且结合模态分解等方法做一次全面的深度学习…

牛客网Java高频面试题(2024最新版含答案)

作为 Java 程序员&#xff0c;选择学习什么样的技术&#xff1f;什么技术该不该学&#xff1f;去招聘网站上搜一搜、看看岗位要求就十分清楚了&#xff0c;自己具备的技术和能力&#xff0c;直接影响到你工作选择范围和能不能面试成功。 如果想进大厂&#xff0c;那就需要在 Ja…

第9章 Apache WEB服务器企业实战

万维网 (WORLD WIDE WEB,WWW)服务器,也称之为WEB服务器,主要功能是提供网上信息浏览服务。WWW是 Internet的多媒体信息查询工具,是Internet上飞快发展的服务,也是目前用的最广泛的服务。正是因为有了WWW软件,才使得近年来 Internet 迅速发展。 目前主流的WEB服务器软件包…

HTML 基础概念:什么是 HTML ? HTML 的构成 与 HTML 基本文档结构

文章目录 什么是 HTML &#xff1f;HTML 的构成 &#xff1f;什么是 HTML 元素&#xff1f;HTML 元素的组成部分HTML 元素的特点 HTML 基本文档结构如何打开新建的 HTML 文件代码查看 什么是 HTML &#xff1f; HTML&#xff08;超文本标记语言&#xff0c;HyperText Markup L…

【Kafka】Windows+KRaft部署指南

【Kafka】Windows+KRaft部署指南 摘要本地环境说明官网快速开始修改config/kraft/server.properties初始化数据存储目录启动测试创建topic创建生产者创建消费者FAQ输入行太长。命令语法不正确。问题描述解决方案参考资料摘要 Kafka是一种高吞吐量的分布式发布订阅消息系统,它…

阿里云-防火墙设置不当导致ssh无法连接

今天学网络编程的时候&#xff0c;看见有陌生ip连接&#xff0c;所以打开了防火墙禁止除本机之外的其他ip连接&#xff1a; 但是当我再次用ssh的时候&#xff0c;连不上了才发现大事不妙。 折腾了半天&#xff0c;发现阿里云上可以在线向服务器发送命令&#xff0c;所以赶紧把2…

Grafana GreptimeDB 数据源插件上线啦,全面替代 Prometheus 插件

为什么创建 GreptimeDB 数据源插件 此前&#xff0c;用户可以通过 Prometheus 数据源插件&#xff0c;设置连接到 GreptimeDB 来进行 PromQL 查询。 GrpetimeDB 支持了 80% 以上的 PromQL 语法。但是&#xff0c;由于 GreptimeDB 底层使用多值模型&#xff0c;而非 Prometheu…

LabVIEW编程过程中为什么会出现bug?

在LabVIEW编程过程中&#xff0c;Bug的产生往往源自多方面原因。以下从具体的案例角度分析一些常见的Bug成因和调试方法&#xff0c;以便更好地理解和预防这些问题。 ​ 1. 数据流错误 案例&#xff1a;在一个LabVIEW程序中&#xff0c;多个计算节点依赖相同的输入数据&#…

WPF+MVVM案例实战(十八)- 自定义字体图标按钮的封装与实现(ABD类)

文章目录 1、案例效果1、按钮分类2、ABD类按钮实现描述1.文件创建与代码实现2、样式引用与控件封装3、按钮案例演示1、页面实现与文件创建2、运行效果如下3、总结4、源代码获取1、案例效果 1、按钮分类 在WPF开发中,最常见的就是按钮的使用,这里我们总结以下大概的按钮种类,…