【问题标题】:Need to create bash script:需要创建 bash 脚本:
【发布时间】:2018-11-12 19:43:12
【问题描述】:

-自动安装泊坞窗。

-获取 3 个 docker 镜像(Apache、Nginx、MariaDB)。

-创建docker-compose.yml文件并进行配置。

-服务应该可以工作:Apache:port 8080 Nginx:port 80 MariaDB:port 4000.

#!bin/bash
sudo yum -y update
sudo tee >/etc/yum.repos.d/docker.repo <<-EOF
[dockerrepo]
name=Docker Repository
baseurl=https://yum.dockerproject.org/repo/main/centos/7/
enabled=1
gpgcheck=1
gpgkey=https://yum.dockerproject.org/gpg
EOF
sudo yum search docker-engine
sudo yum install -y docker-engine
sudo systemctl enable docker.service && systemctl start docker.service
sudo yum -y install epel-release
sudo yum -y install python-pip
sudo pip install docker-compose
sudo tee >/home/ash/docker_project/Dockerfile <<-EOF
FROM httpd:2.4
COPY ./public-html/ /usr/local/apache2/htdocs

FROM nginx
COPY nginx.conf /etc/nginx/nginx.conf

EOF
cd /home/ash/docker_project
sudo tee >/home/ash/docker_project/docker-compose.yml <<-EOF
 version: '3' 

 services:
    apache: 
      image: httpd:2.4 
      ports: 
      - "8080:8080" 
      volumes: 
      - ./src:/usr/local/apache2/htdocs 

    web: 
      image: nginx
      volumes:
       - ./mysite.template:/etc/nginx/conf.d/mysite.template
      ports: 
       - "80:80" 

      command: /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d && nginx -g 'daemon off;'"

    db: 
      image: mariadb 
      ports: 
      - "4000:4000"
EOF
docker-compose up -d

看起来脚本运行正常,终端没有错误所以我的问题是为什么我在 localhost:8080 上看不到 apache 的起始页,与 nginx 和 MariaDB 一样?

所有输出都很长,但这里是主要内容

Starting docker_project_apache_1 ... done
Starting docker_project_web_1    ... done
Starting docker_project_db_1     ... done

当我运行docker images 时,我看到了这个列表:

REPOSITORY          TAG                 IMAGE ID            CREATED
bitnami/apache      latest              569eec9f6f5c        4 days ago       
mariadb             latest              4828ff028cad        8 days ago
nginx               latest              ae513a47849c        4 weeks ago 
httpd               2.4                 fb2f3851a971        4 weeks ago   

【问题讨论】:

  • 你启动 apache 了吗?

标签: bash docker centos docker-compose


【解决方案1】:

httpd docker apache 镜像暴露了 80 端口,而不是 8080,请参见 herehere
只需在 docker-compose 中使用 apache 端口更改行:

  image: httpd:2.4 
  ports: 
  - "8080:8080" 

到:

  image: httpd:2.4 
  ports: 
  - "8080:80" 

apache 应该可以工作了。

@编辑:

对于 mariadb 容器,它暴露了 3306 端口。

至于 nginx,您在 web 服务的 docker-compose 中的命令行中有 bash 错误。 bash 命令:

envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d

会导致 bash 错误,因为 /etc/nginx/conf.d 是一个目录。可能你的意思是:

envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/mysite.conf

【讨论】:

  • 嗯,mariadb 公开了 3306 端口,而不是 4000。这就留下了 nginx,您可以在其中上传自定义配置。检查 nginx 是否已启动 docker-compose 日志。
  • 关于 nginx 日志有这样的输出:"web_1 | /bin/bash: /etc/nginx/conf.d: 是一个目录
  • 编辑了答案; )
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-08-31
  • 1970-01-01
  • 1970-01-01
  • 2013-10-02
  • 2013-03-26
  • 2011-04-27
  • 2016-11-17
相关资源
最近更新 更多