I want to keep my images simple as possible and leave the “configuration” part for docker-compose.yml . This is my configuration now
Nginx image Dockerfile
From centos:7
#Install epel-release repo
RUN yum -y install --setopt=tsflags=nodocs epel-release && \
yum -y install --setopt=tsflags=nodocs nginx && \
yum clean all
EXPOSE 80
EXPOSE 443
#start nginx
CMD [ "nginx", "-g", "daemon off;"]
php-fpm70 image Dockerfile
From centos:7
#Install centos-release-scl-rh
RUN yum install -y --setopt=tsflags=nodocs centos-release-scl-rh && \
yum install -y --setopt=tsflags=nodocs \
rh-php70-php.x86_64 \
rh-php70-php-bcmath.x86_64 \
rh-php70-php-common.x86_64 \
rh-php70-php-devel.x86_64 \
rh-php70-php-enchant.x86_64 \
rh-php70-php-fpm.x86_64 \
rh-php70-php-gd.x86_64 \
rh-php70-php-intl.x86_64 \
rh-php70-php-json.x86_64 \
rh-php70-php-ldap.x86_64 \
rh-php70-php-mbstring.x86_64 \
rh-php70-php-mysqlnd.x86_64 \
rh-php70-php-pear.noarch \
rh-php70-php-pspell.x86_64 \
rh-php70-php-process.x86_64 \
rh-php70-php-recode.x86_64 \
rh-php70-php-snmp.x86_64 \
rh-php70-php-soap.x86_64 \
rh-php70-php-xml.x86_64 \
rh-php70-php-zip.x86_64 && \
yum clean all
EXPOSE 9003
#start php-fpm70
CMD [ "/opt/rh/rh-php70/root/usr/sbin/php-fpm", "--nodaemonize"]
docker-compose.yml
version: "3"
services:
web:
image: nginx
volumes:
- /opt/nginx/nginx.conf:/etc/nginx/nginx.conf
# map /opt/nginx/conf.d/test.conf to /etc/nginx/conf.d/test.conf in container
- /opt/nginx/conf.d:/etc/nginx/conf.d
# map source code folder from host to container
- /opt/www:/opt/www
deploy:
replicas: 2
restart_policy:
condition: on-failure
ports:
- "80:80"
- "443:443"
networks:
- webnet
php-fpm70:
image: php-fpm70
deploy:
replicas: 2
restart_policy:
condition: on-failure
volumes:
# override php-fpm config incontainer
# My www.conf on host has "listen = 127.0.0.1:9003" , I want to change php-fpm port from 9000 #(default) to 9003
- /opt/php-fpm70/www.conf:/etc/opt/rh/rh-php70/php-fpm.d/www.conf
ports:
- "9003:9003"
networks:
- webnet
networks:
webnet:
test.conf
server {
listen 80;
server_name test.mydomain.com;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
root /opt/www/test/;
gzip on;
gzip_comp_level 9;
gzip_min_length 1000;
gzip_proxied off;
gzip_types text/plain text/css application/xml+html application/javascript image/jpeg image/x-icon image/gif image/png video/jpeg;
gzip_disable "MSIE [1-6]\.";
index index.html index.htm index.php;
location / {
try_files $uri $uri/ /index.php?/$request_uri;
}
location ~ \.php$ {
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_read_timeout 150;
fastcgi_pass 127.0.0.1:9003;
fastcgi_index index.php;
}
}
docker stack deploy -c docker-compose.yml getstartedlab
Creating network getstartedlab_webnet
Creating service getstartedlab_web
Creating service getstartedlab_php-fpm70
docker service ls
ID NAME MODE REPLICAS IMAGE PORTS
tvhoegirh0u1 getstartedlab_php-fpm70 replicated 2/2 php-fpm70:latest *:9003->9003/tcp
eyso1a223bpb getstartedlab_web replicated 2/2 nginx:latest *:80->80/tcp, *:443->443/tcp
I can access to test.mydomain.com --> “Welcome to nginx” , but I cannot access test.mydomain.com/abc.php which actually show phpinfo --> “502 Bad Gateway”, here log result
docker service logs getstartedlab_web
getstartedlab_web.2.mqami2228dix@localhost.localdomain | 10.255.0.2 - - [23/Jun/2018:03:04:15 +0000] "GET / HTTP/1.1" 200 1281 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0"
getstartedlab_web.1.kd3jvdlhayoa@localhost.localdomain | 2018/06/23 03:04:15 [error] 7#7: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 10.255.0.2, server: test.mydomain.com, request: "GET /poweredby.png HTTP/1.1", upstream: "fastcgi://127.0.0.1:9003", host: "test.mydomain.com", referrer: "http://test.mydomain.com/"
getstartedlab_web.2.mqami2228dix@localhost.localdomain | 2018/06/23 03:04:15 [error] 7#7: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 10.255.0.2, server: test.mydomain.com, request: "GET /nginx-logo.png HTTP/1.1", upstream: "fastcgi://127.0.0.1:9003", host: "test.mydomain.com", referrer: "http://test.mydomain.com/"
getstartedlab_web.1.kd3jvdlhayoa@localhost.localdomain | 10.255.0.2 - - [23/Jun/2018:03:04:15 +0000] "GET /poweredby.png HTTP/1.1" 502 173 "http://test.mydomain.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0"
getstartedlab_web.2.mqami2228dix@localhost.localdomain | 10.255.0.2 - - [23/Jun/2018:03:04:15 +0000] "GET /nginx-logo.png HTTP/1.1" 502 173 "http://test.mydomain.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0"
getstartedlab_web.2.mqami2228dix@localhost.localdomain | 2018/06/23 03:04:18 [error] 7#7: *3 connect() failed (111: Connection refused) while connecting to upstream, client: 10.255.0.2, server: test.mydomain.com, request: "GET /abc.php HTTP/1.1", upstream: "fastcgi://127.0.0.1:9003", host: "test.mydomain.com"
getstartedlab_web.2.mqami2228dix@localhost.localdomain | 10.255.0.2 - - [23/Jun/2018:03:04:18 +0000] "GET /abc.php HTTP/1.1" 502 173 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:60.0) Gecko/20100101 Firefox/60.0"
Is there something wrong with docker network so nginx container cannot connect with php-fpm70 container ?
docker network ls
NETWORK ID NAME DRIVER SCOPE
6d4cc5aa09f4 bridge bridge local
78fb32ab0e58 docker_gwbridge bridge local
9sxuyuxcwjlq getstartedlab_webnet overlay swarm
270e6709c894 host host local
svsdczo4kr26 ingress overlay swarm
ffbf775e969e none null local
docker network inspect getstartedlab_webnet
[
{
"Name": "getstartedlab_webnet",
"Id": "9sxuyuxcwjlquoqu1zbaz8huf",
"Created": "2018-06-23T10:03:56.620174441+07:00",
"Scope": "swarm",
"Driver": "overlay",
"EnableIPv6": false,
"IPAM": {
"Driver": "default",
"Options": null,
"Config": [
{
"Subnet": "10.0.0.0/24",
"Gateway": "10.0.0.1"
}
]
},
"Internal": false,
"Attachable": false,
"Ingress": false,
"ConfigFrom": {
"Network": ""
},
"ConfigOnly": false,
"Containers": {
"9d30d57e6b1d5f9fd71d4771b760c991d2146b308cf3df74875fd31ecebebf1e": {
"Name": "getstartedlab_web.2.mqami2228dixlrujxwqpncskd",
"EndpointID": "304470a08228b130ed3fadb7f36ccdc2898b9dd3849a5d80a8e03ac9a93e8504",
"MacAddress": "02:42:0a:00:00:05",
"IPv4Address": "10.0.0.5/24",
"IPv6Address": ""
},
"a2a3d652da946138fd6b33ad757540934f055cc01db1cbc344b3619109f72fbb": {
"Name": "getstartedlab_php-fpm70.1.h1ded0ovmlpxdsfwxsps0pbzr",
"EndpointID": "ce27144f8ede515ae1a36b0e44f890d4293cd9d7c0998fa36b4ca01e8c58930d",
"MacAddress": "02:42:0a:00:00:07",
"IPv4Address": "10.0.0.7/24",
"IPv6Address": ""
},
"ea839fff4e013d0f64ff4597bb63910119f41527378b69fa71af1a55d7eb6f56": {
"Name": "getstartedlab_web.1.kd3jvdlhayoayfhhr8bx5mqna",
"EndpointID": "3af0749441b3a5825f0f36fe4c2b1d7565f859baee38f2179cf874824c3ce101",
"MacAddress": "02:42:0a:00:00:04",
"IPv4Address": "10.0.0.4/24",
"IPv6Address": ""
},
"f191bd551d0df8912af64e1b789e1dcb31ac2d01d8e12b3164910815be677d3e": {
"Name": "getstartedlab_php-fpm70.2.l70dy735x4d71z25gkizcyd60",
"EndpointID": "a3a0fd18ed70d5123e66b92fa0ecef781b46b51b6d8a99e007462c87c2044208",
"MacAddress": "02:42:0a:00:00:08",
"IPv4Address": "10.0.0.8/24",
"IPv6Address": ""
}
},
"Options": {
"com.docker.network.driver.overlay.vxlanid_list": "4107"
},
"Labels": {
"com.docker.stack.namespace": "getstartedlab"
},
"Peers": [
{
"Name": "2a7b6aa7e0ce",
"IP": "192.168.0.124"
}
]
}
]
On host, I can see there is nginx and php-fpm containers are runnung, I cant telnet telnet 127.0.0.1 80 but cannot telnet 127.0.0.1 9003.