I have the following docker-compose file :
version: '2'
services:
phpfpm:
tty: true # Enables debugging capabilities when attached to this container.
image: 'bitnami/php-fpm:5.6'
labels:
kompose.service.type: nodeport
ports:
- 9000:9000
volumes:
- /usr/share/nginx/html:/app
networks:
- app-tier
nginx:
image: 'bitnami/nginx:latest'
depends_on:
- phpfpm
networks:
- app-tier
links:
- phpfpm
ports:
- '80:8080'
- '443:8443'
volumes:
- ./my_vhost.conf:/bitnami/nginx/conf/vhosts/vhost.conf
networks:
app-tier:
driver: bridge
and here's the contents of my_vhost.conf file :
server {
listen 0.0.0.0:8080;
root /app;
index index.php index.html index.htm;
location / {
try_files $uri $uri/ =404;
}
location /evodms {
root /app/evodms;
try_files $uri $uri /evodms/index.php?$args;
}
location ~ \.php$ {
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass phpfpm:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}
I have my applications within the /usr/share/nginx/html folder.
I have tried the following links :
http://localhost => works, shows nginx homepage
http://localhost/page.html => just an ordinary html file and works
http://localhost/phpinfo.php => shows the php informations and works
http://localhost/evodms, shows the following error messages from my
docker :
nginx_1 | nginx: [warn] conflicting server name "" on 0.0.0.0:8080,
ignored
nginx_1 | 2017/12/08 15:13:29 [warn] 24#0: conflicting
server name "" on 0.0.0.0:8080, ignored
nginx_1 | 2017/12/08 15:15:04 [error] 25#0: *1 FastCGI sent in
stderr: "PHP message: PHP Warning:
include(/usr/share/nginx/html/evodms/lib/LibCakePhp20unit/lib/Cake/Core/CakePlugin.php):
failed to open stream: No such file or directory in
/app/evodms/lib/LibCakePhp20unit/lib/Cake/Core/App.php on line 505
nginx_1 | PHP message: PHP Warning: include(): Failed opening
'/usr/share/nginx/html/evodms/lib/LibCakePhp20unit/lib/Cake/Core/CakePlugin.php'
for inclusion (include_path='.:/opt/bitnami/php/lib/php') in
/app/evodms/lib/LibCakePhp20unit/lib/Cake/Core/App.php on line 505
nginx_1 | PHP message: PHP Fatal error: Class 'CakePlugin' not
found in /app/evodms/app/Config/bootstrap.php on line 66" while
reading response header from upstream, client: 172.26.0.1, server: ,
request: "GET /evodms/ HTTP/1.1", upstream:
"fastcgi://172.26.0.2:9000", host: "localhost"
nginx_1 | 172.26.0.1 - - [08/Dec/2017:15:15:04 +0000] "GET /evodms/
HTTP/1.1" 500 5 "-" "Mozilla/5.0 (X11; Linux x86_64)
AppleWebKit/537.36 (KHTML, like Gecko) Chrome/61.0.3163.100
Safari/537.36"
Any clue on what's going on for the issue on the last link?
I think you should try with webdevops images which already include php-fpm and a webserver.
version: '3'
services:
app:
image: webdevops/php-nginx:7.2
ports:
- 9080:80
volumes:
- ./:/app
environment:
- PHP_DEBUGGER=xdebug
- PHP_DISPLAY_ERRORS=1
- WEB_DOCUMENT_ROOT=/app/public
Related
I have nginx and metabase in docker. When I try to access "https://MYDOMAIN/metabase" I get the error - connect() failed (111: Connection refused) while connecting to upstream, client: 60.243.254.30, server: MYDOMAIN, request: "GET /metabase/ HTTP/2.0", upstream: "http://127.0.0.1:3000/metabase/", host: "MYDOMAIN".
This works - "curl http://localhost:3000/metabase". This also works - "curl http://127.0.0.1:3000/metabase".
nginx is running fine - I am able to access other sites that are running.
What am I doing wrong in the configuration?
docker-compose.yml
-------------------
webserver:
image: nginx:1.20.0
restart: "no"
volumes:
- ./public:/var/www/html
- ./conf.d:/etc/nginx/conf.d
- ./sites-available:/etc/nginx/sites-available
- ./sites-enabled:/etc/nginx/sites-enabled
- ./ssl:/etc/nginx/ssl
ports:
- '80:80'
- '443:443'
metabase:
image: metabase/metabase:latest
container_name: metabase
restart: "no"
volumes:
- metabase-data:/LOCATION/metabase
ports:
- '3000:3000'
environment:
MB_SITE_URL: http://localhost:3000/metabase
MB_DB_TYPE: postgres
MB_DB_DBNAME: metabase
MB_DB_PORT: 5432
MB_DB_USER: xxxxx
MB_DB_PASS: yyyyyy
nginx conf.d/default.conf
--------------------------
upstream metabase {
server 127.0.0.1:3000;
}
server {
...
location /metabase/ {
proxy_pass http://metabase;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
break;
}
}
When I try to build my Next.JS application, which has a getStaticProps() function to get data from Strapi, the fetch fails. It fails because it is unable to resolve the alias for the Strapi container while building. Is there a way around this? Here's some info. Let me know if more info would be helpful:
Docker version 20.10.14
docker-compose version 1.29.2
Next.JS version 12.1.0
Node.JS version v17.6.0
In my pages/index.tsx file, I have the following:
export async function getStaticProps() {
let data: PageData = null;
try {
const response = await axios.get(
`${process.env.STRAPI_BACKEND_URL}/api/pages?filters[slug]=strapi-sample-homepage-content`,
{
headers: {
Accept: "application/json",
},
timeout: 500,
}
);
data = response.data.data[0].attributes || null;
} catch (error) {
console.log(error);
}
return {
props: {
data,
},
revalidate: 60,
};
}
This is what Next.JS wants to generate statically while building, and it's unable to because it cannot resolve the location of the Strapi container during build.
docker-compose.yml:
version: '3.8'
services:
db-strapi:
image: 'location/of/image'
container_name: db-strapi
restart: always
volumes:
- db-strapi:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${STRAPI_DB_NAME}
- POSTGRES_PASSWORD=${STRAPI_DB_PW}
- POSTGRES_SCHEMA=${STRAPI_DB_SCHEMA}
- POSTGRES_USER=${STRAPI_DB_USER}
strapi-backend:
image: 'location/of/image'
container_name: strapi-backend
environment:
- ADMIN_JWT_SECRET=${STRAPI_ADMIN_JWT_SECRET}
- API_TOKEN_SALT=${STRAPI_API_TOKEN_SALT}
- APP_KEYS=${STRAPI_APP_KEYS}
- DATABASE_CLIENT=${STRAPI_DB_CLIENT}
- DATABASE_HOST=${STRAPI_DB_HOST}
- DATABASE_NAME=${STRAPI_DB_NAME}
- DATABASE_PASSWORD=${STRAPI_DB_PW}
- DATABASE_PORT=${STRAPI_DB_PORT}
- DATABASE_SCHEMA=${STRAPI_DB_SCHEMA}
- DATABASE_USERNAME=${STRAPI_DB_USER}
- JWT_SECRET=${STRAPI_JWT_SECRET}
- NODE_ENV=${STRAPI_NODE_ENV}
ports:
- 1337:1337
depends_on:
- "db-strapi"
db-nextjs:
image: 'location/of/image'
container_name: db-nextjs
restart: always
volumes:
- db-nextjs:/var/lib/postgresql/data
environment:
- POSTGRES_DB=${NEXTJS_DB_NAME}
- POSTGRES_PASSWORD=${NEXTJS_DB_PW}
- POSTGRES_SCHEMA=${NEXTJS_DB_SCHEMA}
- POSTGRES_USER=${NEXTJS_DB_USER}
nextjs-app:
image: 'location/of/image'
container_name: nextjs-app
environment:
- STRAPI_BACKEND_URL
- NEXTJS_DB_URL
- SECRET_COOKIE_PASSWORD
- NEXT_TELEMETRY_DISABLED=1
restart: always
depends_on:
- "db-nextjs"
nginx:
image: 'location/of/image'
container_name: nginx
environment:
- NGINX_SERVER_NAME
- NGINX_STRAPI_SERVER_NAME=${STRAPI_BACKEND_HOST}
- RESOLVER
- ENVIRONMENT
- NGINX_CERTIFICATE_NAME
- NEXTJS_HOST
- STRAPI_HOST
ports:
- 80:80
- 443:443
restart: always
depends_on:
- "nextjs-app"
- "strapi-backend"
volumes:
- certbot_certificates:/etc/letsencrypt
- certbot_challenges:/usr/share/nginx/html/.well-known/acme-challenge
volumes:
db-strapi:
db-nextjs:
certbot_certificates:
certbot_challenges:
In my .env.local file:
STRAPI_BACKEND_HOST="strapi-backend"
STRAPI_BACKEND_PORT="1337"
STRAPI_BACKEND_URL="http://${STRAPI_BACKEND_HOST}:${STRAPI_BACKEND_PORT}"
When I build, I have the following output:
info - Generating static pages (0/7)
info - Generating static pages (1/7)
info - Generating static pages (3/7)
info - Generating static pages (5/7)
Error: getaddrinfo ENOTFOUND strapi-backend
at GetAddrInfoReqWrap.onlookup [as oncomplete] (node:dns:72:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: 'strapi-backend',
config: {
transitional: {
silentJSONParsing: true,
forcedJSONParsing: true,
clarifyTimeoutError: false
},
adapter: [Function: httpAdapter],
transformRequest: [ [Function: transformRequest] ],
transformResponse: [ [Function: transformResponse] ],
timeout: 500,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
validateStatus: [Function: validateStatus],
headers: { Accept: 'application/json', 'User-Agent': 'axios/0.24.0' },
method: 'get',
url: 'http://strapi-backend:1337/api/pages?filters[slug]=strapi-sample-homepage-content',
data: undefined
},
To me, it seems there's no way to resolve this, because Next.js doesn't seem to be on the docker network yet during build. Are there any solutions?
It seems that Docker's hostname resolution does not work during build time. On Mac, you can try STRAPI_BACKEND_HOST = "host.docker.internal". On Linux, using host networking during build worked for me:
nextjs-app:
build:
network: "host"
# ...
network_mode: "host"
This way, you can use STRAPI_BACKEND_HOST = localhost.
I try to set up my own mailserver, Mailcow was recommended.
DNS-provider:
Cloudflare with
CNAME mail.examle.com => examle.com, proxied
Because it is proxies, I cannot use normal ports like mentioned in the docs. Therefore I have to setup some forwarding...
Router:
Fritzbox with port forwadring
2052 => 25
2053 => 465
8080 => 587
2082 => 143
2083 => 993
2086 => 110
2087 => 995
8880 => 4190
Docker:
I use jwilders reverse proxy and it's LE-companion, which works well with everything else I have hosted so far.
${DOCKERDIR}/docker-compose-js.yml
version: '3'
services:
proxy:
build: ./reverse_proxy
container_name: proxy
restart: always
ports:
- 80:80
- 443:443
volumes:
- ${DOCKERDIR}/reverse_proxy/certs:/etc/nginx/certs:ro
- ${DOCKERDIR}/reverse_proxy/vhost.d:/etc/nginx/vhost.d
- ${DOCKERDIR}/reverse_proxy/html:/usr/share/nginx/html
- /var/run/docker.sock:/tmp/docker.sock:ro
environment:
- PUID=33
- PGID=33
labels:
com.github.jrcs.letsencrypt_nginx_proxy_companion.nginx_proxy: ""
networks:
- proxy-tier
depends_on:
- le
le:
image: jrcs/letsencrypt-nginx-proxy-companion
container_name: le
volumes:
- ${DOCKERDIR}/reverse_proxy/certs:/etc/nginx/certs:rw
- ${DOCKERDIR}/reverse_proxy/vhost.d:/etc/nginx/vhost.d
- ${DOCKERDIR}/reverse_proxy/html:/usr/share/nginx/html
- /var/run/docker.sock:/var/run/docker.sock:ro
environment:
- PUID=33
- PGID=33
- DEFAULT_EMAIL=*****
- NGINX_PROXY_CONTAINER=proxy
networks:
- proxy-tier
networks:
proxy-tier:
Then there is a (slightly) modified file for mailcow, just mentioning the changes
%{DOCKERDIR}/mailcow/docker-compose.yml
nginx-mailcow:
...
# ports:
# - "${HTTPS_BIND:-0.0.0.0}:${HTTPS_PORT:-443}:${HTTPS_PORT:-443}"
# - "${HTTP_BIND:-0.0.0.0}:${HTTP_PORT:-80}:${HTTP_PORT:-80}"
...
There seems to be no way to remove those ports from it's original docker-compose.yml despite it not being recommended.
For all other changes I got
${DOCKERDIR}/mailcow/docker-compose-override.yml
version: '2.1'
services:
nginx-mailcow:
networks:
proxy-tier:
environment:
- VIRTUAL_HOST=${MAILCOW_HOSTNAME},${ADDITIONAL_SAN}
- VIRTUAL_PORT=8080
- VIRTUAL_PROTO=http
- LETSENCRYPT_HOST=${MAILCOW_HOSTNAME},${ADDITIONAL_SAN}
volumes:
- ${DOCKERDIR}/reverse_proxy/certs/${MAILCOW_HOSTNAME}:/etc/ssl/mail/
- ${DOCKERDIR}/reverse_proxy/certs/dhparam.pem:/etc/ssl/mail/dhparams.pem:ro
ports:
dovecot-mailcow:
volumes:
- ${DOCKERDIR}/reverse_proxy/certs/${MAILCOW_HOSTNAME}:/etc/ssl/mail/
- ${DOCKERDIR}/reverse_proxy/certs/dhparam.pem:/etc/ssl/mail/dhparams.pem:ro
postfix-mailcow:
volumes:
- ${DOCKERDIR}/reverse_proxy/certs/${MAILCOW_HOSTNAME}:/etc/ssl/mail/
- ${DOCKERDIR}/reverse_proxy/certs/dhparam.pem:/etc/ssl/mail/dhparams.pem:ro
networks:
proxy-tier:
And finally the mailcow.conf (changes only)
${DOCKERDIR}/mailcow/mailcow.conf
MAILCOW_HOSTNAME=mail.example.com
HTTP_PORT=8080
#HTTP_BIND=0.0.0.0
HTTP_BIND=proxy
HTTPS_PORT=8443
#HTTPS_BIND=0.0.0.0
HTTPS_BIND=proxy
SKIP_LETS_ENCRYPT=y
When I try to connect to mail.example.com I get Error 526 Invalid SSL certificate.
Could someone pls show me where my config is wrong and how to change it so I get mailcow working?
I'm starting a springboot app and dynamodb local in docker containers via docker-compose.
Both containers come up successfully.
When I use the container name for the AMAZON_AWS_DYNAMODB_ENDPOINT value, I get the following error:
[https-jsse-nio-8443-exec-6] [2019-04-15 08:03:42,239] INFO com.amazonaws.protocol.json.JsonContent [] - Unable to parse HTTP response content
com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')
at [Source: (byte[])"<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved here.</p>
</body></html>
Further down I'm getting the following error:
com.amazonaws.services.dynamodbv2.model.AmazonDynamoDBException: null (Service: AmazonDynamoDBv2; Status Code: 301; Error Code: null; Request ID: null)
If I replace the AMAZON_AWS_DYNAMODB_ENDPOINT value with my Windows computer IP address (running the containers) it works successfully.
Any suggestions on how to get the container name working?
Here's my docker-compose:
version: '3'
services:
dynamodb:
image: amazon/dynamodb-local
ports:
- "8000:8000"
volumes:
- dynamodata:/data
command: "-jar DynamoDBLocal.jar -sharedDb -dbPath ."
app:
build: .
ports:
- "8443:8443"
environment:
- SERVER_PORT=8443
- SERVER_SSL_KEY_STORE=/etc/ssl/key
- SERVER_SSL_KEY_STORE_TYPE=PKCS12
- SERVER_SSL_KEY_ALIAS=tomcat
- SERVER_SSL_KEY_STORE_PASSWORD=xxxxxx
- SPRING_PROFILES_ACTIVE=aws,local
- DATAPOWER_ENABLED=true
# - AMAZON_AWS_DYNAMODB_ENDPOINT=${DYNAMODB_ENDPOINT:-http://dynamodb:8000} <--- does not work
# - AMAZON_AWS_DYNAMODB_ENDPOINT=${DYNAMODB_ENDPOINT:-http://xx.xxx.xxx.xxx:8000} <--- works
- AMAZON_AWS_DYNAMODB_REGION=${DYNAMODB_REGION:-us-east-1}
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID:-local}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY:-xxxxxxxxxx}
- ENV=dev
- AWS_REGION=us-east-1
volumes:
dynamodata:
Thanks
Try adding networks something like this:
version: '3'
services:
dynamodb:
image: amazon/dynamodb-local
ports:
- "8000:8000"
volumes:
- dynamodata:/data
command: "-jar DynamoDBLocal.jar -sharedDb -dbPath ."
networks:
- my-network
app:
build: .
ports:
- "8443:8443"
environment:
- SERVER_PORT=8443
- SERVER_SSL_KEY_STORE=/etc/ssl/key
- SERVER_SSL_KEY_STORE_TYPE=PKCS12
- SERVER_SSL_KEY_ALIAS=tomcat
- SERVER_SSL_KEY_STORE_PASSWORD=xxxxxx
- SPRING_PROFILES_ACTIVE=aws,local
- DATAPOWER_ENABLED=true
# - AMAZON_AWS_DYNAMODB_ENDPOINT=${DYNAMODB_ENDPOINT:-http://dynamodb:8000} <--- does not work
# - AMAZON_AWS_DYNAMODB_ENDPOINT=${DYNAMODB_ENDPOINT:-http://xx.xxx.xxx.xxx:8000} <--- works
- AMAZON_AWS_DYNAMODB_REGION=${DYNAMODB_REGION:-us-east-1}
- AWS_ACCESS_KEY_ID=${AWS_ACCESS_KEY_ID:-local}
- AWS_SECRET_ACCESS_KEY=${AWS_SECRET_ACCESS_KEY:-xxxxxxxxxx}
- ENV=dev
- AWS_REGION=us-east-1
networks:
- my-network
volumes:
dynamodata:
networks:
my-network:
driver: bridge
Can someone help me to connect my PHP and MySQL
I did manage to make it up and running, connect to DB with MySQL Workbench but when I try PDO connect from PHP file it fails for some reason...
docker-compose
web:
image: nginx:latest
ports:
- "80:80"
volumes:
- ./:/var/www
- ./site.conf:/etc/nginx/conf.d/site.conf
links:
- php
php:
image: php:7-fpm
volumes:
- ./:/var/www
links:
- db
db:
image: mysql:5.7
volumes:
- /var/lib/mysql
environment:
- MYSQL_ROOT_PASSWORD=123456
- MYSQL_DATABASE=database
ports:
- "3306:3306"
site.conf
server {
index index.php index.html;
server_name lara.test;
error_log /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /var/www;
location ~ \.php$ {
try_files $uri =404;
fastcgi_split_path_info ^(.+\.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_param PATH_INFO $fastcgi_path_info;
}
}
and index.php
<?php
$database = new PDO('mysql:host=localhost;dbname=database', "root", "123456");
echo "Connected to MySQL<br />";
?>
and error message:
Fatal error: Uncaught PDOException: could not find driver in
/var/www/index.php:3 Stack trace: #0 /var/www/index.php(3):
PDO->__construct('mysql:host=loca...', 'root', '123456') #1 {main}
thrown in /var/www/index.php on line 3
what do I miss in order to make this work?
Just change
$database = new PDO('mysql:host=localhost;dbname=database', "root",
"123456");
to
$database = new PDO('mysql:host=db;dbname=database', "root", "123456");
the name of host must same with the name of database image on docker-compose file.