验证docker是否安装成功:

root@FLKY:/etc/docker# sudo docker run hello-world
Unable to find image 'hello-world:latest' locally
latest: Pulling from library/hello-world
17eec7bbc9d7: Pull complete 
Digest: sha256:54e66cc1dd1fcb1c3c58bd8017914dbed8701e2d8c74d9262e26bd9cc1642d31
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/



出现Hello from Docker!说明安装成功!

然后我们将当前用户加入到docker的用户组

配置用户组

root@FLKY:/etc/docker# sudo usermod -aG  docker flky
root@FLKY:/etc/docker# su - flky  # 刷新shell状态
flky@FLKY:~$ docker images
REPOSITORY    TAG       IMAGE ID       CREATED       SIZE
hello-world   latest    1b44b5a3e06a   5 weeks ago   10.1kB

查看状态(active启动)

flky@FLKY:~$ sudo systemctl status docker
[sudo] password for flky: 
● docker.service - Docker Application Container Engine
     Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
     Active: active (running) since Sat 2025-09-13 17:00:27 CST; 5min ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 8056 (dockerd)
      Tasks: 10
     Memory: 22.8M
        CPU: 1.264s
     CGroup: /system.slice/docker.service
             └─8056 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock

913 17:00:26 FLKY dockerd[8056]: time="2025-09-13T17:00:26.686565958+08:00" level=info msg="Loading containers: start."
913 17:00:27 FLKY dockerd[8056]: time="2025-09-13T17:00:27.427975945+08:00" level=warning msg="Error (Unable to complete atomic operation, key modified) deleting object [endpoint_count cad786b663069c1ee093b87e814d5faff8a78ee872306cebdad23efd8b42f73>
9月 13 17:00:27 FLKY dockerd[8056]: time="2025-09-13T17:00:27.523885052+08:00" level=info msg="Loading containers: done."
9月 13 17:00:27 FLKY dockerd[8056]: time="2025-09-13T17:00:27.575894431+08:00" level=info msg="Docker daemon" commit=249d679 containerd-snapshotter=false storage-driver=overlay2 version=28.4.0
9月 13 17:00:27 FLKY dockerd[8056]: time="2025-09-13T17:00:27.576541754+08:00" level=info msg="Initializing buildkit"
9月 13 17:00:27 FLKY dockerd[8056]: time="2025-09-13T17:00:27.627715588+08:00" level=info msg="Completed buildkit initialization"
9月 13 17:00:27 FLKY dockerd[8056]: time="2025-09-13T17:00:27.651225147+08:00" level=info msg="Daemon has completed initialization"
9月 13 17:00:27 FLKY dockerd[8056]: time="2025-09-13T17:00:27.651623910+08:00" level=info msg="API listen on /run/docker.sock"
9月 13 17:00:27 FLKY systemd[1]: Started Docker Application Container Engine.
9月 13 17:01:42 FLKY dockerd[8056]: time="2025-09-13T17:01:42.605124207+08:00" level=info msg="ignoring event" container=ce54211cdfa5f44b74bd80a5d8bf0eecf534bfe6fbb6132dc3e17568e94d6938 module=libcontainerd namespace=moby topic=/tasks/delete type="*ev>

启动


flky@FLKY:~$ sudo systemctl start docker

开启自启动

flky@FLKY:~$ sudo systemctl enable docker
Synchronizing state of docker.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable docker

查看docker信息

flky@FLKY:~$ docker info
Client: Docker Engine - Community
 Version:    28.4.0
 Context:    default
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.27.0
    Path:     /usr/libexec/docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.39.2
    Path:     /usr/libexec/docker/cli-plugins/docker-compose

Server:
 Containers: 1
  Running: 0
  Paused: 0
  Stopped: 1
 Images: 1
 Server Version: 28.4.0
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: systemd
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 CDI spec directories:
  /etc/cdi
  /var/run/cdi
 Swarm: inactive
 Runtimes: nvidia runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 05044ec0a9a75232cad458027ca83437aae3f4da
 runc version: v1.2.5-0-g59923ef
 init version: de40ad0
 Security Options:
  apparmor
  seccomp
   Profile: builtin
  cgroupns
 Kernel Version: 6.8.0-79-generic
 Operating System: Ubuntu 22.04.5 LTS
 OSType: linux
 Architecture: x86_64
 CPUs: 2
 Total Memory: 3.778GiB
 Name: FLKY
 ID: 17316e1c-d8fe-4c8e-a104-a3561977e259
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 Experimental: false
 Insecure Registries:
  ::1/128
  127.0.0.0/8
 Registry Mirrors:
  https://docker.m.daocloud.io/
  https://huecker.io/
  https://dockerhub.timeweb.cloud/
  https://noohub.ru/
  https://dockerproxy.com/
  https://docker.mirrors.ustc.edu.cn/
  https://docker.nju.edu.cn/
  https://xx4bwyg2.mirror.aliyuncs.com/
  http://f1361db2.m.daocloud.io/
  https://registry.docker-cn.com/
  http://hub-mirror.c.163.com/
 Live Restore Enabled: false

2、dokcer安装emqx

1.运行以下命令获取 Docker 镜像:

docker pull emqx/emqx-enterprise:5.10.0

2.运行以下命令启动 Docker 容器。

docker run -d --name emqx-enterprise -p 1883:1883 -p 8083:8083 -p 8084:8084 -p 8883:8883 -p 18083:18083 emqx/emqx-enterprise:5.10.0

3.Docker 部署注意事项

  • 如果需要持久化 Docker 容器中生成的数据 ,请将以下目录挂载到容器外部,这样即使容器被删除数据也不会丢失:
/opt/emqx/data
/opt/emqx/log
  • 关于 EMQX 目录结构的详细信息请参考 EMQX 文件和目录。

  • 启动容器并挂载目录:

docker run -d --name emqx-enterprise \
  -p 1883:1883 -p 8083:8083 \
  -p 8084:8084 -p 8883:8883 \
  -p 18083:18083 \
  -v $PWD/data:/opt/emqx/data \
  -v $PWD/log:/opt/emqx/log \
  emqx/emqx-enterprise:5.10.0
  • Docker 内的 localhost 或 127.0.0.1 指向的是容器内部地址,如需访问宿主机地址请使用宿主机的真实 IP 或使用 host 网络模式。如果您使用的是 Docker for Mac 或 Docker for Windows,可以使用 host.docker.internal 作为宿主机地址。
  • 由于 EMQX 使用 data/mnesia/<节点名> 作为数据存储目录,请使用 FQDN 等固定的信息作为节点名,避免因为节点名称变动导致数据丢失。
  1. 常用命令:
  • 查看现有容器: docker ps -a,找到 emqx-enterprise 对应的容器 ID。

  • 如果不需要旧的容器,直接删除:docker rm -f emqx-enterprise

  • 如果想保留旧容器,可以换一个名字:

    docker run -d --name emqx-enterprise2 \
    -p 1883:1883 -p 8083:8083 \
    -p 8084:8084 -p 8883:8883 \
    -p 18083:18083 \
    -v $PWD/data:/opt/emqx/data \
    -v $PWD/log:/opt/emqx/log \
    emqx/emqx-enterprise:5.10.0   
    
    
  • 如果只是想启动之前的容器,而不是新建:

docker start emqx-enterprise

Logo

码道开发者社区,聚焦华为云码道 CodeArts 代码智能体,沉淀 Agent、Skill、鸿蒙开发实战内容,供开发者查阅资料、交流技术、分享工程实践

更多推荐