docker安装apache

如何使用docker安装apache

Linux终端

方式/步骤

  1. 1

    查找Docker Hub上的apache镜像

    [root@localhost ~]# docker search httpd

    241f95cad1c8a786e984f3cf6909c93d71cf5040.jpg
  2. 2

    拉取官方的镜像

    [root@localhost ~]# docker pull httpd

    0df3d7ca7bcb0a465b2032f86563f6246a60aff5.jpg
  3. 3

    查看镜像

    [root@localhost ~]# docker images httpd

    c9fcc3cec3fdfc03a0075a79da3f8794a5c226f7.jpg
  4. 4

    利用apache默认的设置装备摆设来启动一个apache容器

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

    1ad5ad6eddc451dabf48b52ab8fd5266d11632b0.jpg
  5. 5

    建立apache目次

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

    a8773912b31bb05188920ae9387adab44bede0b9.jpg
  6. 6

    拷贝容器内apache默认设置装备摆设文件到当地apache的conf目次

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

    c2cec3fdfc039245e52b58ce8994a4c27c1e2550.jpg
  7. 7

    遏制apache容器

    [root@localhost ~]# docker stop apache

    9213b07eca806538c2731dd299dda144ac348252.jpg
  8. 8

    删除apache容器

    [root@localhost ~]# docker rm apache

    8326cffc1e178a82d1efc661f803738da877e824.jpg
  9. 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

    cdbf6c81800a19d8aece3dc43dfa828ba71e4625.jpg
  10. 10

    查看建立的容器

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

    86d6277f9e2f0708553f92c1e724b899a901f23d.jpg
  11. 11

    查看容器的ip地址

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

    e61190ef76c6a7ef3ce911e7f3faaf51f2de6620.jpg
  12. 12

    查看firewalld状况

    [root@localhost ~]# systemctl status firewalld

    42a98226cffc1e17ed6235f04490f603728de916.jpg
  13. 13

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

    [root@localhost ~]# systemctl start firewalld

    0bd162d9f2d3572c9dd5241d8413632762d0c338.jpg
  14. 14

    开放80端口

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

    8b13632762d0f703027a2c1d06fa513d2797c523.jpg
  15. 15

    从头载入

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

    cefc1e178a82b90123677af27d8da9773812ef2d.jpg
  16. 16

    查看是否生效

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

    4d086e061d950a7b85edf70504d162d9f3d3c913.jpg
  • 发表于 2019-08-29 20:51
  • 阅读 ( 701 )
  • 分类:其他类型

相关问题

0 条评论

请先 登录 后评论