-Autoinstall docker。
- 获得3个泊坞窗图像(Apach,Nginx,MariaDB)。
创建docker-compose.yml
文件并进行配置。
- 服务应该工作:Apache:端口8080 Nginx:端口80 MariaDB:端口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时,我看不到apache的启动页面:8080与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
答案 0 :(得分:1)
httpd
docker apache图像公开端口80,而不是8080,请参阅here或here。
只需在docker-compose中使用apache端口更改行:
image: httpd:2.4
ports:
- "8080:8080"
为:
image: httpd:2.4
ports:
- "8080:80"
和apache应该正常工作。
@edit:
对于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