网上介绍fedora容器非常少,基本都是ubutun容器。fedora容器使用过程还是遇到一些小问题,有必要单独说明下。
使用前面介绍的容器启动方式,我们新建fedora基础容器,常用的包如下(和ubuntu有点差异):
dnf install vim -y
dnf install iputils -y
dnf install net-tools -y
dnf install python3-pip -y
dnf install curl -y
dnf install wget -y
dnf install gcc -y
dnf install g++ -y
dnf install ruby -y
dnf install java-latest-openjdk.aarch64 -y
# 清除缓存
dnf clean all
对于Fedora容器安装ssh服务器,默认就没有那么容易了。安装ssh服务器,但是无法启动,可能遇到以下的问题:
service sshd
无法启动service sshd
The service command supports only basic LSB actions (start, stop, restart, try-restart, reload, reload-or-restart, try-reload-or-restart, force-reload, status, condrestart). For other actions, please try to use systemctl.
systemctl start sshd
无法启动systemctl start sshd
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
/usr/sbin/init
无法启动容器systemctl
命令。sudo docker run -i -t -d -v /share:/share -p 12122:22 --privileged=true --name fdocker2 --hostname fdocker2 fedora:latest /usr/sbin/init
6b7aa89a4b8bc3e3fb6514e468c79a95697f02d89378280cfd8bd910ba36ce57
docker: Error response from daemon: failed to create shim task: OCI runtime create failed: runc create failed: unable to start container process: exec: "/usr/sbin/init": stat /usr/sbin/init: no such file or directory: unknown.
解决的办法是我们自己制作镜像,先使用下面的命令启动容器:
sudo docker run -i -t -d -v /share:/share -p 12122:22 --privileged=true --name fdocker2 --hostname fdocker2 fedora:latest /bin/bash
然后安装initscripts
包,并导出镜像。
# 安装包
dnf install initscripts -y
#导出镜像
docker export -o fedora0.tar fdocker2
docker import fedora0.tar
docker tag xxx local-fedora:v1.0
# 启动docker
sudo docker run -i -t -d -v /share:/share -p 13122:22 --privileged=true --name fdocker3 --hostname fdocker3 fedora:latest /usr/sbin/init
# 进入docker
sudo docker exec -it fdocker3 bash
# 安装ssh服务器
dnf install openssh-server
service start sshd
使用本地制作的镜像,重新拉起新的容器,就可以使用systemctl
启动sshd
服务了。
# service启动
service start sshd
# 或者
systemctl start sshd