【摸鱼日常】使用httpd部署捕鱼达人小游戏

  一、捕鱼达人小游戏介绍

1.1 捕鱼达人是一款经典街机游戏,玩家的目标是在限定的时间内捕获尽可能多的鱼类以获得高分。游戏开始后,屏幕上会出现不同种类和大小的鱼类,每个鱼类都有自己的得分。玩家需要操作炮台,控制方向和角度,发射炮弹来捕获鱼类。一旦炮弹命中鱼类,它们就会被捕获并获得相应的分数。游戏还提供了多个级别,随着级别的提高,鱼类的难度和数量也会增加。

1.2 这个开源项目在github上。

github地址:https://github.com/sjh0824/Fishing-talentGame

如果用github打不开,可以通过该地址git clone。如果不想打开,下面已经拉取了代码下来放在百度云的,永久自取。

https://githubfast.com/sjh0824/Fishing-talentGame

 二、本次实践介绍

1. 本次实践简介

本次实践部署环境为个人测试环境,先游戏的源代码在github下载下来,另外已经百度云存了一份,可以直接下载。

拉取的命令:git clone https://githubfast.com/sjh0824/Fishing-talentGame.git

百度云:https://pan.baidu.com/s/1sml-CUs97cM8HXlcSqSh3Q 提取码: 25nz

2. 本地环境规划

本次实践环境规划:docker快速拉取httpd,然后后台启动httpd,数据持久化到你的项目挂载路径。

启动镜像后的名字 IP地址 容器镜像版本 操作系统版本
httpd 192.168.20.8 latest ubuntu 22.04

三、检查本地Docker环境

  1. 检查本地Docker版本

检查Docker版本:docker version

root@WellDone:/home/goodjob/Downloads# docker ps
CONTAINER ID   IMAGE                                                     COMMAND                   CREATED       STATUS        PORTS                                       NAMES
59840bc170bd   registry.cn-guangzhou.aliyuncs.com/welldene/games:mario   "python3 -m http.ser…"   3 hours ago   Up 3 hours    0.0.0.0:8888->8080/tcp, :::8888->8080/tcp   mario
be18fd5e0c64   postgres:latest                                           "docker-entrypoint.s…"   2 days ago    Up 29 hours   0.0.0.0:5432->5432/tcp, :::5432->5432/tcp   postgres
6fd5132cfcec   redis:latest                                              "docker-entrypoint.s…"   2 days ago    Up 29 hours   0.0.0.0:6379->6379/tcp, :::6379->6379/tcp   redis
root@WellDone:/home/goodjob/Downloads# 

 2. 检查Docker服务状态

检查Docker服务状态,确保Docker服务正常运行。

systemctl status docker

root@WellDone:/home/goodjob/Downloads# 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; 1 day 4h ago
TriggeredBy: ● docker.socket
       Docs: https://docs.docker.com
   Main PID: 1549 (dockerd)
      Tasks: 65
     Memory: 419.5M
        CPU: 38.874s
     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
             ├─123083 /usr/bin/docker-proxy -proto tcp -host-ip 0.0.0.0 -host-port 8888 -container-ip 172.17.0.4 -container-port 8080
             └─123095 /usr/bin/docker-proxy -proto tcp -host-ip :: -host-port 8888 -container-ip 172.17.0.4 -container-port 8080

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.
1月 24 16:13:48 WellDone dockerd[1549]: time="2024-01-24T16:13:48.185008219+08:00" level=info msg="ignoring event" container=8ad99af82d8a41dd661d>
1月 24 16:13:48 WellDone dockerd[1549]: time="2024-01-24T16:13:48.189484205+08:00" level=warning msg="ShouldRestart failed, container will not be>
1月 24 21:58:08 WellDone dockerd[1549]: time="2024-01-24T21:58:08.024915139+08:00" level=info msg="ignoring event" container=27fd28e2993f31b170b8>
1月 24 21:58:08 WellDone dockerd[1549]: time="2024-01-24T21:58:08.029986730+08:00" level=warning msg="ShouldRestart failed, container will not be>
1月 25 10:46:16 WellDone dockerd[1549]: time="2024-01-25T10:46:16.329180722+08:00" level=info msg="Container failed to exit within 10s of signal >
1月 25 10:46:16 WellDone dockerd[1549]: time="2024-01-25T10:46:16.350757439+08:00" level=info msg="ignoring event" container=b1223add00f36bbb3246>
1月 25 10:49:21 WellDone dockerd[1549]: time="2024-01-25T10:49:21.993755983+08:00" level=info msg="Container failed to exit within 10s of signal >
1月 25 10:49:22 WellDone dockerd[1549]: time="2024-01-25T10:49:22.015822650+08:00" level=info msg="ignoring event" container=edb0e153b45dbe62acd8>
lines 1-28/28 (END)

四、部署httpd镜像

1. 下载httpd镜像

部署httpd不需要这么麻烦了,只需要在docker上面拉取所需镜像即可。

docker pull httpd

[root@welldeng welldeng]# docker pull httpd
Using default tag: latest
latest: Pulling from library/httpd
2f44b7a888fa: Pull complete 
376771e8483c: Pull complete 
4f4fb700ef54: Pull complete 
6a6627aecff0: Pull complete 
152f4888b550: Pull complete 
fd0579f22872: Pull complete 
Digest: sha256:ba846154ade27292d216cce2d21f1c7e589f3b66a4a643bff0cdd348efd17aa3
Status: Downloaded newer image for httpd:latest
docker.io/library/httpd:latest
[root@welldeng welldeng]# docker images
REPOSITORY                                          TAG       IMAGE ID       CREATED        SIZE
httpd                                               latest    2cfd65f8d6ff   9 days ago     167MB
tomcat                                              latest    f42b2599b503   5 weeks ago    454MB
nginx                                               latest    a6bd71f48f68   2 months ago   187MB
registry.cn-guangzhou.aliyuncs.com/welldene/games   v1.0      a3cf6b941e08   2 years ago    31.5MB
twang2218/gitlab-ce-zh                              latest    18da462b5ff5   5 years ago    1.61GB
2. 创建容器

使用docker快速创建httpd的容器。由于docker具有隔离性,所以我们要把配置文件和存放代码的文件路径挂载出来,我这里为了方便,直接进入docker下的httpd,把这个httpd复制了出来进行挂载。

创建思路:先用docker创建httpd的容器,复制容器的内容到你挂载的路径,然后编辑httpd的配置文件去掉报错,然后把游戏的源码放到httpd的读取路径,然后停止并删除httpd容器,根据挂载的路径和需要的端口进行docker命令开启游戏。

完整创建过程:

1.首先,先启动一个httpd的测试容器。

docker run -d -p 18888:80 httpd:latest

2.启动完毕后查看httpd的容器id

docker ps

[root@welldeng welldeng]# docker run -d -p 18888:80 httpd:latest
28ad60ac5756172ba473beca591d30ae0a0587a2c420061b7c08bed849bd5735
[root@welldeng welldeng]# docker ps
CONTAINER ID   IMAGE           COMMAND                  CREATED         STATUS        PORTS                                       NAMES
28ad60ac5756   httpd:latest    "httpd-foreground"       2 seconds ago   Up 1 second   0.0.0.0:18888->80/tcp, :::18888->80/tcp     laughing_wu

3.先在软件存放的目录/opt下创建httpd的文件路径,然后把容器内的httpd相关的内容复制到此路径

docker cp 28ad60ac5756:/usr/local/apache2 /opt/httpd

4.复制完后停掉这个容器并删除

docker stop 28ad60ac5756

docker rm 28ad60ac5756

5.然后使用docker启动httpd,挂载当前的复制出来的文件到容器内,这样便于在宿主机去更改httpd的配置以及程序的update

docker run -d -p 18888:80 -v /opt/httpd/apache2:/usr/local/apache2 --name httpd httpd:latest

6.把下载好的adarkroom-main复制到/opt/httpd/apache2/htdocs下面,这里是能够让httpd读到程序的路径。

7.httpd刚开启启动会有一个报错,如

AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using localhost.localdomain. Set the 'ServerName' directive globally to suppress this message

这个是配置文件上的问题,用vim打开/opt/httpd/apache2/conf/httpd.conf,全局搜索ServerName,把ServerName后面的内容改为localhost:80。

命令如下:

vim /opt/httpd/apache2/conf/httpd.conf

:set number #打开vim内的行数导航

?ServerName  #全局搜索ServerName

然后enter,然后键盘输入i,开启可编辑模式。

把ServerName后面的内容改为localhost:80

然后键盘点击esc,输入:wq便保存成功。

8.重启httpd容器

docker restart httpd



​​​3. 检查容器运行状态

检查容器的运行状态,确保服务的正常运行。

docker ps

五、访问游戏模拟器的web页面

访问游戏模拟器首页 访问地址:http://192.168.20.8:18888/Fishing-talentGame

在浏览器进入捕鱼达人小游戏页面。

 

你可能感兴趣的:(docker小游戏,docker,容器,运维)