Linux终端
查找Docker Hub上的apache镜像
[root@localhost ~]# docker search httpd
拉取官方的镜像
[root@localhost ~]# docker pull httpd
查看镜像
[root@localhost ~]# docker images httpd
利用apache默认的设置装备摆设来启动一个apache容器
[root@localhost ~]# docker run -d -p 80:80 --name apache httpd:latest
建立apache目次
[root@localhost ~]# mkdir -p /usr/local/apache/www /usr/local/apache/logs /usr/local/apache/conf
拷贝容器内apache默认设置装备摆设文件到当地apache的conf目次
[root@localhost ~]# docker cp apache:/usr/local/apache2/conf/httpd.conf /usr/local/apache/conf
遏制apache容器
[root@localhost ~]# docker stop apache
删除apache容器
[root@localhost ~]# docker rm apache
建立并运行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
查看建立的容器
[root@localhost ~]# docker ps | grep apache
查看容器的ip地址
[root@localhost ~]# docker inspect --format='{{.NetworkSettings.IPAddress}}' apache
查看firewalld状况
[root@localhost ~]# systemctl status firewalld
开启firewalld(可选,未开启时执行)
[root@localhost ~]# systemctl start firewalld
开放80端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=80/tcp --permanent
从头载入
[root@localhost ~]# firewall-cmd --reload
查看是否生效
[root@localhost ~]# firewall-cmd --zone=public --query-port=80/tcp
0 篇文章
如果觉得我的文章对您有用,请随意打赏。你的支持将鼓励我继续创作!