后面开发环境实际上就是在docker安装的centos8上面安装各类开发使用的软件,即centos8安装httpd
1.用yum安装httpd
命令为:yum install httpd,后续直接输入y确认(当然也可以在install前面加上 -y 不用手动确认),一直到出现Complete!为止
命令:yum install httpd
2.设置httpd服务随系统一起启动
命令:systemctl enable httpd
[root@0f095f9b6160 /]# systemctl enable httpd
Created symlink /etc/systemd/system/multi-user.target.wants/httpd.service → /usr/lib/systemd/system/httpd.service.
[root@0f095f9b6160 /]#
3.启动httpd服务
命令:systemctl start httpd
哦哦 报错了"System has not been booted with systemd as init system (PID 1). Can't operate.Failed to connect to bus: Host is down",如遇到这个问题是创建镜像和启动容器方式有问题, 请参照打造专属的docker开发环境(一)-centos安装
[root@0f095f9b6160 /]# systemctl start httpd
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
正常情况启动成功没有任何报错信息
[root@54aa323af4dd /]# systemctl start httpd
[root@54aa323af4dd /]#
4.查看httpd服务
命令:systemctl status httpd
[root@54aa323af4dd /]# systemctl status httpd
● httpd.service - The Apache HTTP Server
Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-06-29 03:32:17 UTC; 3min 56s ago
Docs: man:httpd.service(8)
Main PID: 189 (httpd)
Status: "Running, listening on: port 80"
Tasks: 213 (limit: 42049)
Memory: 15.7M
CGroup: /docker/54aa323af4dda02b7af488eacfb237bb81e273b5cec4cdc45c9a97c9361bb0a7/system.slice/httpd.service
├─189 /usr/sbin/httpd -DFOREGROUND
├─190 /usr/sbin/httpd -DFOREGROUND
├─191 /usr/sbin/httpd -DFOREGROUND
├─192 /usr/sbin/httpd -DFOREGROUND
└─193 /usr/sbin/httpd -DFOREGROUND
Jun 29 03:32:17 54aa323af4dd systemd[1]: Starting The Apache HTTP Server...
Jun 29 03:32:17 54aa323af4dd httpd[189]: AH00558: httpd: Could not reliably determine the server's fully qualified domain name, using 172.17.0.2. Set the 'ServerName' dir>
Jun 29 03:32:17 54aa323af4dd systemd[1]: Started The Apache HTTP Server.
Jun 29 03:32:17 54aa323af4dd httpd[189]: Server configured, listening on: port 80
lines 1-19/19 (END)
输入 冒号:及q 退出
4.测试在系统中访问服务
命令: curl http://127.0.0.1:80
应该返回html页面
5.在本机访问docker中的centos系统中的httpd服务,需要先把容器创建为镜像 再通过80端口映射出来,才可以访问
5.1 找出容器ID
命令:docker ps -a
(base) wangheng@localhost ~ % docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f0404b39ed3f quay.io/centos/centos "/usr/sbin/init" 4 minutes ago Up 4 minutes centos7-wh-dev
5.2 将容器ID创建为镜像
命令: docker commit -a "wh" -m "centos7+httpd" f0404b39ed3f centos7-wh-dev:v1
(base) wangheng@localhost ~ % docker commit -a "wh" -m "centos7+httpd" f0404b39ed3f centos7-wh-dev:v1
5.3 查看镜像
命令: docker images
(base) wangheng@localhost ~ % docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos7-wh-dev v1 7f25397cb37b 32 seconds ago 255MB
5.4 从新建的镜像启动容器
新增了run 的-p参数
命令:docker run -p 80:80 -itd --privileged --name centos7-wh-dev-v1 centos7-wh-dev:v1 /usr/sbin/init
(base) wangheng@localhost ~ % docker run -p 80:80 -itd --privileged --name centos7-wh-dev-v1 centos7-wh-dev:v1 /usr/sbin/init
3c9c4cf21c1f18bbfb5a4651df6278dc0f59fee84396b4156c29b887c8b98749
(base) wangheng@localhost ~ %
6.在浏览器中输入http://localhost/ 有centos提供的页面表示httpd服务在启作用
7.自己建立一个页面通过浏览器访问
进入容器
docker exec -it centos7-wh-dev-v1 /bin/bash
进入 /var/www/html/ 目录创建一个index.html
[root@a2b08ad4465e /]# cd /var/www/html/
[root@a2b08ad4465e html]# vi index.html
docker命令大全
https://www.runoob.com/docker/docker-run-command.html