linux下Docker安装Apache

1.查找Docker Hub上的apache镜像

[root@localhost ~]# docker search httpd

2.拉取官方的镜像

[root@localhost ~]# docker pull httpd

3.查看镜像

[root@localhost ~]# docker images httpd

4.使用apache默认的配置来启动一个apache容器

[root@localhost ~]# docker run -d -p 80:80 --name apache httpd:latest

5.创建apache目录

[root@localhost ~]# mkdir -p /usr/local/apache/www /usr/local/apache/logs /usr/local/apache/conf

6.拷贝容器内apache默认配置文件到本地apache的conf目录

[root@localhost ~]# docker cp apache:/usr/local/apache2/conf/httpd.conf /usr/local/apache/conf

7.停止apache容器

[root@localhost ~]# docker stop apache

8.删除apache容器

[root@localhost ~]# docker rm apache

9.创建并运行apache容器

[root@localhost ~]# docker run -d -p 80:80 --name apache -v /usr/local/apache/www:/usr/local/apache2/htdocs/ -v /usr/local/apache/conf/httpd.conf:/usr/local/apache2/conf/httpd.conf -v /usr/local/apache/logs:/usr/local/apache2/logs --restart=always httpd:latest

10.查看创建的容器

[root@localhost ~]# docker ps | grep apache

11.查看容器的ip地址

[root@localhost ~]# docker inspect --format='{{.NetworkSettings.IPAddress}}' apache

12.查看firewalld状态

[root@localhost ~]# systemctl status firewalld

13.开启firewalld(可选,未开启时执行)

[root@localhost ~]# systemctl start firewalld

14.开放80端口

[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent

15.重新载入

[root@localhost ~]# firewall-cmd --reload

16.查看是否生效

[root@localhost ~]# firewall-cmd --zone=public --query-port=80/tcp

 

你可能感兴趣的:(docker,linux,apache)