一、本次实践介绍
1. 本次实践简介
本次实践部署环境为个人测试环境,快速使用docker部署2048小游戏。
root@WellDone:/home/goodjob# uname -a
Linux WellDone 6.5.0-14-generic #14~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Mon Nov 20 18:15:30 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
2. 本地环境规划
本次实践环境规划:
启动镜像后的名字 | IP地址 | 容器镜像版本 | 操作系统版本 |
---|---|---|---|
2048 | 192.168.2.76 | latest | ubuntu 22.04 |
二、Docker环境
1.检查本地Docker版本
检查Docker版本:docker version
root@WellDone:/home/goodjob# docker version
Client: Docker Engine - Community
Version: 25.0.0
API version: 1.44
Go version: go1.21.6
Git commit: e758fe5
Built: Thu Jan 18 17:09:49 2024
OS/Arch: linux/amd64
Context: default
Server: Docker Engine - Community
Engine:
Version: 25.0.0
API version: 1.44 (minimum version 1.24)
Go version: go1.21.6
Git commit: 615dfdf
Built: Thu Jan 18 17:09:49 2024
OS/Arch: linux/amd64
Experimental: false
containerd:
Version: 1.6.27
GitCommit: a1496014c916f9e62104b33d1bb5bd03b0858e59
runc:
Version: 1.1.11
GitCommit: v1.1.11-0-g4bccb38
docker-init:
Version: 0.19.0
GitCommit: de40ad0
2. 检查Docker服务状态
检查Docker服务状态,确保Docker服务正常运行。
systemctl status docker
root@WellDone:/home/goodjob# systemctl status docker
● docker.service - Docker Application Container Engine
Loaded: loaded (/lib/systemd/system/docker.service; enabled; vendor preset: enabled)
Active: active (running) since Wed 2024-01-24 08:54:31 CST; 7h ago
TriggeredBy: ● docker.socket
Docs: https://docs.docker.com
Main PID: 1549 (dockerd)
Tasks: 66
Memory: 178.0M
CPU: 6.959s
CGroup: /system.slice/docker.service
├─ 1549 /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
├─ 2010 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 6379 -container-ip 172.17.0.2 -container-port 6379
├─ 2016 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 6379 -container-ip 172.17.0.2 -container-port 6379
├─ 2029 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 5432 -container-ip 172.17.0.3 -container-port 5432
├─ 2036 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 5432 -container-ip 172.17.0.3 -container-port 5432
├─26709 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8888 -container-ip 172.17.0.4 -container-port 80
└─26716 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8888 -container-ip 172.17.0.4 -container-port 80
1月 24 08:54:30 WellDone dockerd[1549]: time="2024-01-24T08:54:30.147900140+08:00" level=info msg="Starting up"
1月 24 08:54:30 WellDone dockerd[1549]: time="2024-01-24T08:54:30.150167308+08:00" level=info msg="detected 127.0.0.53 nameserver, assuming syste>
1月 24 08:54:30 WellDone dockerd[1549]: time="2024-01-24T08:54:30.222187838+08:00" level=info msg="[graphdriver] using prior storage driver: over>
1月 24 08:54:30 WellDone dockerd[1549]: time="2024-01-24T08:54:30.253670047+08:00" level=info msg="Loading containers: start."
1月 24 08:54:30 WellDone dockerd[1549]: time="2024-01-24T08:54:30.660930678+08:00" level=info msg="Default bridge (docker0) is assigned with an I>
1月 24 08:54:31 WellDone dockerd[1549]: time="2024-01-24T08:54:31.025018910+08:00" level=info msg="Loading containers: done."
1月 24 08:54:31 WellDone dockerd[1549]: time="2024-01-24T08:54:31.037721980+08:00" level=info msg="Docker daemon" commit=615dfdf containerd-snaps>
1月 24 08:54:31 WellDone dockerd[1549]: time="2024-01-24T08:54:31.037911963+08:00" level=info msg="Daemon has completed initialization"
1月 24 08:54:31 WellDone dockerd[1549]: time="2024-01-24T08:54:31.067895045+08:00" level=info msg="API listen on /run/docker.sock"
1月 24 08:54:31 WellDone systemd[1]: Started Docker Application Container Engine.
三、部署2048小游戏
1. 下载2048小游戏容器镜像
拉取镜像:docker pull 镜像
docker pull quchaonet/2048
2. 创建2048容器
使用docker-cli快速创建2048小游戏的容器。
docker run -d -p 1111:8080 --name 2048 quchaonet/2048:latest
本次实践部署使用docker compose方式,编辑docker-compose.yml文件。
version: '3.9'
services:
'2048':
image: 'quchaonet/2048:latest'
container_name: '2048'
ports:
- '1111:8080'
3. 检查容器运行状态
检查容器的运行状态,确保2048小游戏的正常运行。
docker psroot@WellDone:/opt/docker-compose/docker-games# docker compose ps
NAME IMAGE COMMAND SERVICE CREATED STATUS PORTS
2048 quchaonet/2048:latest "/bin/sh -c 'nginx -…" 2048 51 minutes ago Up 51 minutes 0.0.0.0:1111->8080/tcp, :::1111->8080/tcp
四、访问2048小游戏的web页面
访问地址:http://192.168.20.8:1111/