Website blank while running nginx and wordpress through docker - linux

I've been following a tutorial to setup a website on a raspberry pi using docker.
I'm running the following in my yaml file:
version: "3.7"
services:
db:
build: ./db
container_name: db
ports:
- "3306:3306"
volumes:
- db_data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: *Blocking out my password*
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: *Blocking out my password*
networks:
website_network:
aliases:
- wordpress
wordpress:
build: .
container_name: wordpress
ports:
- "80"
networks:
website_network:
aliases:
- wordpress
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: *Blocking out my password*
WORDPRESS_DB_NAME: wordpress
nginx:
build: ./nginx
container_name: nginx
ports:
- "443:443"
- "80"
networks:
website_network:
aliases:
- nginx-proxy
networks:
website_network:
name: website_network
volumes:
db_data:
driver: local
name: db_data
I have some additional files which are taking the wildcard encyption files, unzipping them and running them inside the nginx container. My problem is that when I run all the containers, the website "appears" but its basically a blank screen. my code doesn't have any typos from what I can tell, so I'm a bit stuck. I think that my cointainers aren't really talking to each other anymore. The encrpyting works since the website is accessible through https:
I don't know if I can be help, but I've been stuck for about a week now and I'm at a loss. I might just find another tutorial.
Ive been trying to recheck the code, uninstalling images and reinstalling them using docker-compose prune or docker container --remove-orphans, etc. I've tried taking it down and putting it back up, building the containers first but nothing seems to help. I'm really stuck. My guess is it's something stupid and I'm just missing it.

Related

Portainer / Docker-Compose execute "RUN docker-php-ext-install pdo_mysql"

I am trying to make Docker Container that hosts a Website that uses .php and mysql . I am using this docker-compose:
version: '3'
services:
mariadb:
image: mariadb:10.6
restart: always
environment:
MYSQL_ROOT_PASSWORD: pw
MYSQL_USER: user
MYSQL_PASSWORD: pw
ports:
- "9906:3306"
volumes:
- ./mariadb/db:/var/lib/mysql
php:
image: php:apache
ports:
- 8050:80
volumes:
- ./website/web:/var/www/html
When I try to use the Website it says couldnt find drivers. To solve this I have to put this command
"RUN docker-php-ext-install pdo_mysql" into a Dockerfile. But since I use docker-compose with Portainer I dont quite know how to make it run the command.
I tried to make envoriment variables or running it via console but that didnt work

Is it possible to mount my existing Mongo DataBase with docker-compose?

After some months of development I got to a point where it is better to dockerize my MERN application. I managed to create .yaml file and everything is working OK but the problem is that I already have big amount of data that is collected. I want to be able to mount this data to container but I don't know how to do it. Read a lot of stuff but still my data is not appearing after composing the applications. Here is how my docker-compose.yaml file looks-like:
version: '3.9'
services:
#MongoDB Service
mongo_db:
container_name: db_container
image: mongo:latest
restart: always
ports:
- 2717:27017
volumes:
- /mnt/c/temp/mongo/db:/data/db
#Node API Service
api:
build: .
ports:
- 4001:4001
environment:
PORT: 4001
MONGODB_URI: mongodb://db_container:27017
DB_NAME: project-system
depends_on:
- mongo_db
volumes:
mongo_db:
As you can see in this row:
volumes:
- /mnt/c/temp/mongo/db:/data/db
I am trying to point the path from my C:\ drive but this doesn't work. I also tried the same row in:
volumes:
mongo_db:
(the bottom of file) but again without success. Basically my existing DB is on
C:\data\db
How can I point this to be the source of MongoDB service?
First, you need to create the dump from local MongoDB and copy those files to docker MongoDB. You can use these commands to create:
mongodump --uri 'mongodb://localhost:27017/yourdatabase' --archive=<your file> --gzip
mongorestore --uri 'mongodb://remotehost:27017/yourdatabase' --archive=<your file> --gzip
You should be able to access the docker from local host.
Note: Reference this answer if you don't get it correct.
You can do these changes on the path you are mounting to make data persistent. Create a new folder C:/data/docker_mongo to make data persistent.
version: '3.9'
services:
#MongoDB Service
mongo_db:
container_name: db_container
image: mongo:latest
restart: always
ports:
- 2717:27017
volumes:
- C:/data/docker_mongo:/data/db
#Node API Service
api:
build: .
ports:
- 4001:4001
environment:
PORT: 4001
MONGODB_URI: mongodb://db_container:27017
DB_NAME: project-system
depends_on:
- mongo_db
volumes:
mongo_db:

Node.js is not running in Docker is my docker-compose.yml correct?

The problem:
I'm trying to set up a Docker WordPress development environment on Windows 11 with wsl2. I created a docker-compose.yml and everything works apart from the node install. The container tries to start it and then just stops. Is something in my docker-compose file wrong?
I want to use node because I use gulp, npm and browser sync for my WordPress themes.
This is my docker-compose.yml:
version: "3.9"
services:
db:
image: mysql:5.7
volumes:
- dbdata:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
volumes:
- wp-content:/var/www/html/wp-content
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
node:
restart: "no"
image: node:latest
container_name: nodejs
depends_on:
- wordpress
volumes:
- node-data:/usr/src/app
ports:
- 3000:3000
- 3001:3001
volumes:
dbdata:
wp-content:
node-data:
You have to use a Dockerfile otherwise it will never ever work!
Problem is that you have mentioned to spin up the docker container but just think for a sec how will you command node to tell that what it needs to do .When it sees no action commanded it basically closes up .
Solution
Long way - You can use up a dockerfile, as mentioned by Tom , dockerfile is generally used to containerise your application so whatever code you need do just write it , then build your code into a docker image with node using Dockerfile , but in that case trouble is that everytime you are doing any code change you have reiterate over the same process and again build your code.
Another simple way I could think of is add a command:npm start in your node image and this should help you probably
Forgive me if I have suggested something wrong because I am also learner in docker :)

Traefik: all subdirectories return 404

First, thank you in advance for taking a look. I think I have a very basic mistake somewhere, but I have searched for hours with no result. I am trying to run a proof of concept to expose a container behind a traefik 2.4 reverse proxy at a subdirectory. My DDNS does not allow for subdomains, so I am stuck with subdirectories until I can prove this works.
My problem is every container I stand up is dynamically picked up by traefik and shows up in the dashboard, but the subdirectory gives a 404 error. I have even used PathPrefix with a regex to prevent the ending / error.
Here is my configuration.
Traefik's docker-compose:
version: '3'
services:
traefik:
image: traefik:v2.4
container_name: traefik
restart: unless-stopped
security_opt:
- no-new-privileges:true
networks:
- t2_proxy
ports:
- 80:80
- 443:443
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data/traefik.yml:/traefik.yml:ro
- ./data/acme.json:/acme.json
- ./data/log:/var/log
labels:
- "traefik.enable=true"
- "traefik.http.routers.traefik.entrypoints=http"
- "traefik.http.routers.traefik.rule=Host(`domain.host.com`)"
- "traefik.http.middlewares.traefik-auth.basicauth.users=user:password"
- "traefik.http.middlewares.traefik-https-redirect.redirectscheme.scheme=https"
- "traefik.http.routers.traefik.middlewares=traefik-https-redirect"
- "traefik.http.routers.traefik-secure.entrypoints=https"
- "traefik.http.routers.traefik-secure.rule=Host(`domain.host.com`)"
- "traefik.http.routers.traefik-secure.middlewares=traefik-auth"
- "traefik.http.routers.traefik-secure.tls=true"
- "traefik.http.routers.traefik-secure.tls.certresolver=http"
- "traefik.http.routers.traefik-secure.service=api#internal"
fail2ban:
image: crazymax/fail2ban:latest
container_name: fail2ban
network_mode: "host"
cap_add:
- NET_ADMIN
- NET_RAW
volumes:
# - /var/log:/var/log:ro
- ./fail2ban/data:/data
- ./data/log:/var/log:ro
networks:
t2_proxy:
external: true
Here is my traefik.yml configuration file:
api:
dashboard: true
entryPoints:
http:
address: ":80"
https:
address: ":443"
providers:
docker:
endpoint: "unix:///var/run/docker.sock"
exposedByDefault: false
certificatesResolvers:
http:
acme:
email: email#email.com
storage: acme.json
httpChallenge:
entrypoint: http
log:
filePath: "/var/log/traefik.log"
level: DEBUG
accessLog:
filePath: "var/log/access.log"
filters:
statusCodes:
- "400-499"
retryAttempts: true
Here is the first proof-of-concept container I'm trying to expose. It's just portainer in a separate docker-compose:
version: '3'
services:
portainer:
image: portainer/portainer-ce:latest
container_name: portainer
restart: unless-stopped
security_opt:
- no-new-privileges:true
networks:
- t2_proxy
ports:
- "9000:9000"
volumes:
- /etc/localtime:/etc/localtime:ro
- /var/run/docker.sock:/var/run/docker.sock:ro
- ./data:/data
labels:
- "traefik.enable=true"
#web routers
- "traefik.http.routers.portainer.entrypoints=http"
- "traefik.http.routers.portainer.rule=Host(`domain.host.com`) && PathPrefix(`/portainer`)"
#- "traefik.http.routers.portainer.rule=Host(`domain.host.com`) && PathPrefix(`/portainer{regex:$$|/.*}`)"
#- "traefik.http.routers.portainer.rule=Path(`/portainer`)"
#- "traefik.http.routers.portainer.rule=PathPrefix(`/portainer{regex:$$|/.*}`)"
#middlewares
#- "traefik.http.routers.portainer.middlewares=portainer-stripprefix"
#- "traefik.http.middlewares.portainer-stripprefix.stripprefix.prefixes=/portainer"
- "traefik.http.middlewares.portainer-https-redirect.redirectscheme.scheme=https"
- "traefik.http.routers.portainer.middlewares=portainer-https-redirect"
#web secure rpiters
- "traefik.http.routers.portainer-secure.entrypoints=https"
- "traefik.http.routers.portainer-secure.rule=Host(`domain.host.com`) && PathPrefix(`/portainer`)"
#- "traefik.http.routers.portainer-secure.rule=Host(`domain.host.com`) && PathPrefix(`/portainer{regex:$$|/.*}`)"
#- "traefik.http.routers.portainer-secure.rule=Path(`/portainer`)"
#- "traefik.http.routers.portainer-secure.rule=PathPrefix(`/portainer{regex:$$|/.*}`)"
#- "traefik.http.routers.portainer-secure.middlewares=chain-basic-auth#users"
- "traefik.http.routers.portainer-secure.tls=true"
- "traefik.http.routers.portainer-secure.tls.certresolver=http"
- "traefik.http.routers.portainer-secure.service=portainer"
- "traefik.http.services.portainer.loadbalancer.server.port=9000"
- "traefik.docker.network=t2_proxy"
networks:
t2_proxy:
external: true
In summary, I navigate to domain.host.com, and it behaves properly by redirecting me to domain.host.com/dashboard. However, when I go to domain.host.com/portainer it gives a 404 error.
Please let me know if I should post any other details. I sense I am missing a very obvious bit of configuration, as this is my first time using Traefik. Thanks again for any help!
For future googlers
Alright, I figured it out tonight. Thank you, reddit.com/traefik user /u/Quafeinum for trying to help! I actually read the guide here: https://spad.uk/practical-configuration-of-traefik-as-a-reverse-proxy-for-docker/ by spad on linuxserver.io which helped me understand the labels better. The crux of the problem was
traefik.http.services.whoami-whoami.loadbalancer.server.scheme=https
Whatever that does, it was in all the examples, and I mindlessly copied it (there's a cautionary tale here). After removing it, the containers are properly exposed on HTTPS now. Verified with portainer and whoami.
Here is a link to a pastebin of the relevant docker-composes and yamls. This will get a functioning traefik that dynamically loads docker container whoami over HTTPS.
https://pastebin.com/AfBdz6Qm

Azure Docker compose fails with the environment section

I have a docker-compose.yml script working well in Azure. But when I add en environment section with two variables then it fails with this error:
2018-08-24 10:29:30.214 ERROR - Exception in multi-container config parsing: System.InvalidCastException: Specified cast is not valid.
at LWAS.Kube.ComposeFileParser.ParseContainer (System.Collections.Generic.KeyValuePair`2[TKey,TValue] service) [0x00152] in <029f376c1c6a4bb79892c2f60333c2d8>:0
at LWAS.Kube.ComposeFileParser.ParseFile (System.String composeYaml) [0x000d2] in <029f376c1c6a4bb79892c2f60333c2d8>:0
at LWAS.Kube.PodSpec.LoadSpecFromComposeYamlFile (System.String composeFile) [0x00000] in <029f376c1c6a4bb79892c2f60333c2d8>:0
at LWAS.SiteStartInfoRepository.SetupPodSpecForMultiContainerApp (Microsoft.Web.Hosting.StartSiteContext ctx, LWAS.LinuxSiteStartInfo startInfo) [0x0000f] in <029f376c1c6a4bb79892c2f60333c2d8>:0
2018-08-24 10:29:30.215 ERROR - Start multi-container app failed
Shortened content of the docker-compose.yml file is:
version: '3.3'
services:
application:
image: myregistry.azurecr.io/application:latest
volumes:
- application_data:/usr/local/application/data
proxy:
image: myregistry.azurecr.io/proxy:latest
depends_on:
- application
environment:
- NGINX_HOST=myapplication.azurewebsites.net
- NGINX_PORT=80
ports:
- "80:80"
volumes:
application_data:
I tried:
to have only one variable
to use quotes around values i.e. NGINX_PORT="80"
to have whole variable definition in quotes i.e. "NGINX_PORT=80"
to rename variables using camel case i.e. nginxPort=80
to move environment section up and down
Nothing helped - still the same error message.
But it should be possible to use environment variables in Azure with Docker compose as it is shown here: https://learn.microsoft.com/en-us/dotnet/standard/microservices-architecture/multi-container-microservice-net-applications/multi-container-applications-docker-compose
Note: it works locally using docker-compose command without any problem. So it must be some Azure specific problem.
What am I doing wrong?
Thank you
Try:
- Removing the dashes in front of the environment values
- Changing '=' to ': ' for all environment values
version: '3.3'
services:
application:
image: myregistry.azurecr.io/application:latest
volumes:
- application_data:/usr/local/application/data
proxy:
image: myregistry.azurecr.io/proxy:latest
depends_on:
- application
environment:
NGINX_HOST: myapplication.azurewebsites.net
NGINX_PORT: 80
ports:
- "80:80"
volumes:
application_data:
Example yml from Microsoft:
version: '3.3'
services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress
wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
volumes:
db_data:
Source:
https://learn.microsoft.com/en-us/azure/app-service/containers/tutorial-multi-container-app

Resources