x86架构ubuntu22用docker部署zsnes

0. 环境


x86 ubuntu22

1. 安装docker

$ sudo apt remove docker docker-engine docker
$ sudo apt update
$ sudo apt install -y apt-transport-https ca-certificates curl software-properties-common

$ curl -fsSL http://mirrors.aliyun.com/docker-ce/linux/ubuntu/gpg | sudo apt-key add -
$ sudo add-apt-repository "deb [arch=amd64] https://mirrors.aliyun.com/docker-ce/linux/ubuntu $(lsb_release -cs) stable"
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 7EA0A9C3F273FCD8

$ sudo apt update
$ sudo apt install docker-ce docker-ce-cli containerd.io

$ sudo systemctl status docker
$ sudo systemctl restart docker

$ sudo docker run hello-world

x86架构ubuntu22用docker部署zsnes_第1张图片

 


2. 构建docker镜像 

创建文件夹并添加配置

$ cd ~/
$ mkdir docker_zsnet
$ cd docker_zsnet
$ mkdir apt

2.1 创建文件 apt/source.list

deb http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-proposed main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ bionic-backports main restricted universe multiverse

2.2 创建文件 start.sh

#!/bin/bash
#mosquitto -c /etc/mosquitto/mosquitto.conf &
zsnes &

2.3 创建文件 Dockerfile

FROM ubuntu:18.04
#COPY apt/sources.list /etc/apt/
RUN dpkg --add-architecture i386 && \
    apt-get -y update && \
    apt -y install zsnes xarclock
     

COPY start.sh /root/
WORKDIR /root
#EXPOSE 11883
CMD ["bash","-c","./start.sh start && tail -f /dev/null"]

这是目录:

xxjianvm@xxjianvm-virtual-machine:~/work/docker_zsnes$ tree
.
├── apt
│   └── sources.list
├── Dockerfile
└── start.sh

1 directory, 3 files
xxjianvm@xxjianvm-virtual-machine:~/work/docker_zsnes$ 


    
3. 构建并运行docker镜像

 


ubuntu22 操作docker指令需要sudo,因此这里先切换到root用户

$ sudo -s

进入Dockerfile所在目录运行自动构建镜像:

$ docker build -t docker_zsnet:v0.1 .

完成构建后运行:

$ apt-get install x11-xserver-utils
$ xhost + #这个指令每次重启需要执行一次
$ docker run -d -it -v /tmp/.x11-unix:/tmp/.x11-unix -e DISPLAY=unix$DISPLAY -e GDK_SCALE -e GDK_DPI_SCALE --net=host docker_zsnet:v0.1 /bin/bash

这段参数是使能docker运行带界面的程序:

-v /tmp/.x11-unix:/tmp/.x11-unix -e DISPLAY=unix$DISPLAY -e GDK_SCALE -e GDK_DPI_SCALE --net=host 

暂时未实现完全自动化部署,需要执行以下指令:

$ docker ps
CONTAINER ID   IMAGE               COMMAND       CREATED          STATUS          PORTS     NAMES
59393c59aec2   docker_zsnet:v0.1   "/bin/bash"   58 seconds ago   Up 57 seconds             wonderful_mendel
$ docker exec -it wonderful_mendel bash
# chmod +x start.sh

# ./start.sh

注意以上指令中,$是在ubuntu22宿主机执行,#是在docker镜像内执行。

x86架构ubuntu22用docker部署zsnes_第2张图片

docker内的zsnes是可以持续运行的。

x86架构ubuntu22用docker部署zsnes_第3张图片

4. 附docker的一些基本操作


4.1 列出所有镜像

docker ps -a

4.2 删除不要的镜像

 docker rm laughing_napier

4.3 命令行进入镜像

列出正在运行的镜像
docker ps

进入镜像
docker exec -it wonderful_mendel bash

你可能感兴趣的:(架构,docker,容器,游戏程序)