Docker redirect automatically from port 8000 to 8080 - Docker Bug - windows

I've a problem with my Docker.
I use Docker Desktop version 20.10.2, build 2291f61 and docker-compose version 1.27.4, build 40524192 on Windows 10 Pro.
Since a few hours, when I launch any docker-compose and I'm going on my browser to contact localhost:8000, I'm automatically redirect to localhost:8080.
I've delete all my Docker data (images, containers, networks...), I've also reset Docker to factory defaults but that didn't solve anything... I don't know what is going on !
Here, an example of one of my docker-compose.yml :
version: "3.7"
services:
wordpress:
image: wordpress:php7.4-fpm
container_name: e2i-scollado-cours-wordpress
restart: unless-stopped
ports:
- 8000:80
environment:
WORDPRESS_DB_HOST: db
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: password
WORDPRESS_DB_NAME: wordpress
volumes:
- ./storage/wordpress:/var/www/html
networks:
- e2i-scollado-cours
db:
image: mariadb:10.5
container_name: e2i-scollado-cours-database
restart: unless-stopped
ports:
- 3306:3306
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: password
volumes:
- ./storage/database:/var/lib/mysql
networks:
- e2i-scollado-cours
phpmyadmin:
image: phpmyadmin
container_name: e2i-scollado-cours-phpmyadmin
restart: unless-stopped
ports:
- 8080:80
environment:
- PMA_ARBITRARY=1
- PMA_HOSTS=database
- PMA_USER=wordpress
- PMA_PASSWORD=password
networks:
- e2i-scollado-cours
networks:
e2i-scollado-cours:
driver:
bridge
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2e6c54623675 wordpress:php7.4-fpm "docker-entrypoint.s…" 17 minutes ago Up 17 minutes 9000/tcp, 0.0.0.0:8000->80/tcp e2i-scollado-cours-wordpress
bbfb12fa4c14 mariadb:10.5 "docker-entrypoint.s…" 17 minutes ago Up 17 minutes 0.0.0.0:3306->3306/tcp e2i-scollado-cours-database
243fc759179c phpmyadmin "/docker-entrypoint.…" 17 minutes ago Up 17 minutes 0.0.0.0:8080->80/tcp e2i-scollado-cours-phpmyadmin
If I want to see Wordpress on my browser, I'm automatically redirect to PHPMyAdmin in this case.
But, even if I don't had a service on the port 8080, I'm still redirect to the port 8080.
Also, I've this problem with all of my docker-compose, here, it's just an example...
Please, if anyone have an answer, help me please ^^
Thank's

Related

com.mysql.cj.jdbc.exceptions.CommunicationsException: Communications link failure [duplicate]

This question already has answers here:
Docker Compose + Spring Boot + Postgres connection
(4 answers)
Closed 2 months ago.
I have a problem when i try to run my api container that should connect to the db container.
The problem should be appearing when building the project or creating the image, because if i just run the project it successfully connect every time to the container.
Here i have my Dockerfile
FROM openjdk:11
RUN mkdir -p /app/
ADD build/libs/core-0.0.1-SNAPSHOT.jar /app/core-0.0.1-SNAPSHOT.jar
ENTRYPOINT ["java", "-jar", "/app/core-0.0.1-SNAPSHOT.jar"]
Also here the docker-compose.yml file
version: '3.8'
services:
book-catalog-db:
container_name: mysqlbc
image: mysql:latest
volumes:
- ./proyecto/sql-data/db:/var/lib/mysql
ports:
- 3306:3306
hostname: localhost
environment:
MYSQL_USER: 'admin'
MYSQL_PASSWORD: 'admin'
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_ROOT_PASSWORD: 'root'
book-catalog-angular:
container_name: angularbc
image: book-catalog-client:latest
volumes:
- ./proyecto/web-assets:/usr/share/nginx/html/assets
ports:
- 4200:80
book-catalog-api:
container_name: apibc
image: coreapi:latest
ports:
- 8080:8080
I hope i get an answer fast since i dont have much time.
Good day to everyone!
i tried some things of this answer
ok, so i used
docker inspect -f '{{range.NetworkSettings.Networks}}{{.IPAddress}}{{end}}' mysqlbc
i got ip address from mysql container and i changed ip address on project built image,
NOW IT WORKS

Trouble with connecting PostgreSQL in docker-compose

I am trying to create a Laravel project on Docker with a PostgreSQL database locally. The structure of my project is described below:
nginx
conf.d
default.conf
php
Dockerfile
src
Laravel Project
docker-compose-yml
I can run the project successfully on the 8080 port, but I'm having trouble connecting to PostgreSQL.
Here is my docker-compose.yml:
version: '3.8'
networks:
laravel:
services:
nginx:
image: nginx:alpine
command: nginx -g "daemon off;"
container_name: nginx
ports:
- "8080:80"
volumes:
- ./src:/var/www
- ./nginx/conf.d/:/etc/nginx/conf.d
depends_on:
- php
networks:
- laravel
php:
build:
context: ./php
dockerfile: Dockerfile
volumes:
- ./src:/var/www
ports:
- "9000:9000"
networks:
- laravel
db:
container_name: postgres
image: postgres
environment:
- POSTGRES_PASSWORD=password
- POSTGRES_USER=root
- POSTGRES_HOST_AUTH_METHOD=trust
- POSTGRES_DB=expense
volumes:
- ./postgres:/var/lib/postgresql/data"
ports:
- "5446:5432"
restart: always
networks:
- laravel
In case you want to know, here is the Dockerfile for PHP:
FROM php:8.0.3-fpm
RUN docker-php-ext-install pdo
And also I want to mention the .env that is used by Laravel project:
DB_CONNECTION=pgsql
DB_HOST=postgres
DB_PORT=5432
DB_DATABASE=postgres
with this configuration first I've run the docker-compose build and after running the docker-compose up I'm getting the below result for Postgres:
And when I want to reach 127.0.0.1:5432 there's nothing to show me. How can I solve this problem?
In your service db your POSTGRES_DB=expense set the default database name to expense (doc)
So your .env should use DB_DATABASE=expense and not postgres
And a last thing I am not sure about (because I can't find the documentation about it) is your DB_HOST: I don't know if you should use the container_name -> postgres or the service_name -> db, I think it's the service_name so db in your case

Cannot access laravel debugging

I'm having a hard time connecting to the development webserver inside the container (from safari on my host machine).
Since I am using network_mode: host I did not expect there to be any errors.
In my .env APP_URL is set to localhost.com - I added an entry to /etc/hosts accordingly.
Ping localhost.com referes to 127.0.0.1 so that should not be the issue.
version: '3'
services:
setup:
image: mariadb:latest
command:
- mysql -u root -proot -e "CREATE DATABASE central;"
web:
image: waryor/laravel-8.0:latest
volumes:
- '..:/var/www/html'
depends_on:
- mariadb
- redis
stdin_open: true
tty: true
network_mode: host
mariadb:
image: mariadb:latest
environment:
MYSQL_ROOT_PASSWORD: 'root'
MYSQL_DATABASE: 'central'
MYSQL_USER: 'root'
MYSQL_PASSWORD: 'root'
network_mode: host
restart: always
redis:
image: arm64v8/redis:alpine
restart: always
healthcheck:
test: ["CMD", "redis-cli", "ping"]
retries: 3
timeout: 5s
network_mode: host
Starting the webserver works without any errors
root#docker-desktop:/var/www/html# php artisan serve
Starting Laravel development server: http://127.0.0.1:8000
[Wed Oct 6 00:20:54 2021] PHP 8.0.11 Development Server (http://127.0.0.1:8000) started
I've even tried using the --host 0.0.0.0 option without any success.
You need to expose the ports. You don't have to use network_mode. Change your file to:
web:
image: waryor/laravel-8.0:latest
volumes:
- '..:/var/www/html'
ports:
- 80:8000
depends_on:
- mariadb
- redis
stdin_open: true
tty: true
network_mode: host
By doing - 80:8000, you are exposing internal 8000 to external 80, so you can go to localhost and done.

Docker-compose for production running laravel with nginx on azure

I have an app that is working but I am getting problems to make it run on Azure.
I have the next docker-compose
version: "3.6"
services:
nginx:
image: nginx:alpine
volumes:
- ./:/var/www/
- ./setup/azure/nginx/conf.d/:/etc/nginx/template
environment:
PORT: ${PORT}
command: /bin/sh -c "envsubst '$${PORT}' < /etc/nginx/template/nginx.conf.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
networks:
- mynet
depends_on:
- app
- worker
app:
image: myimage:latest
build:
context: .
dockerfile: ./setup/azure/Dockerfile
restart: unless-stopped
tty: true
expose:
- 9000
volumes:
- uploads:/var/www/simple/public/uploads
- logos:/var/www/simple/public/logos
networks:
- mynet
worker:
image: my_image:latest
command: bash -c "/usr/local/bin/php artisan queue:work --timeout=0"
depends_on:
- app
networks:
- mynet
volumes:
uploads:
logos:
networks:
mynet:
I am unsure if the volumes in nginx ok, I think that perhaps I should create a new Dockerfile to copy the files. However, this would increase a lot the size of the project.
When using App Services on azure the development is made assigning a randomly port, that's wgy i have the envsubst instruction in command. I appreciate any other suggestion to make it run this project on Azure
I'm assuming you're trying to persist the storage in your app to a volume. Check out this doc issue. Now I don't think you need
volumes:
- ./:/var/www/
- ./setup/azure/nginx/conf.d/:/etc/nginx/template
but for
volumes:
- uploads:/var/www/simple/public/uploads
- logos:/var/www/simple/public/logos
you can create a storage account, mount it to your linux app plan (it's not available for Windows app plans yet), and mount the relative path /var/www/simple/public/uploads to the file path of the storage container.

Laravel on Docker: [2002] Connection refused

I am trying to put a Laravel app up on Docker, but the database container is giving me trouble.
Specifically, I am getting this error when I try to open the app in the browser:
SQLSTATE[HY000] [2002] Connection refused
But, as far as I can see, all the user credentials are correct. Perhaps I am missing something? Please see below.
docker-compose.yml:
version: '3'
services:
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./yoga/:/var/www
environment:
- "DB_PORT=33061"
- "DB_HOST=database"
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
ports:
- 8080:80
database:
image: mysql:5.7
container_name: database
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=yogadb"
- "MYSQL_USER=yogi"
- "MYSQL_PASSWORD=mypasshere"
- "MYSQL_ROOT_PASSWORD="
ports:
- "33061:3306"
volumes:
dbdata:
.env:
DB_CONNECTION=mysql
DB_HOST=database
DB_PORT=3306
DB_DATABASE=yogadb
DB_USERNAME=yogi
DB_PASSWORD=mypasshere
When I run the app outside docker, everything works correctly, I just replace DB_HOST=database with DB_HOST=127.0.0.1
What can I do to fix this?
docker ps output is:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
2da7283f7a65 docker_app "docker-php-entrypoi…" 19 minutes ago Up 7 seconds 9000/tcp docker_app_1
4801fe3312c1 mysql:5.7 "docker-entrypoint.s…" 2 hours ago Up 7 seconds 33060/tcp, 0.0.0.0:33061->3306/tcp 4801fe3312c1_database
ab370ae1d155 docker_web "nginx -g 'daemon of…" 25 hours ago Up 7 seconds 443/tcp, 0.0.0.0:8080->80/tcp docker_web_1
As #prd mentioned, you need to create bridged network for the containers [1], then add containers to the network [2].
Hostname of container is determined by name of the service in docker-compose.yml. In your case, if app service will connect to database service at hostname database & port 3306.
So docker-compose.yml becomes:
version: '3'
services:
app:
build:
context: ./
dockerfile: app.dockerfile
working_dir: /var/www
volumes:
- ./yoga/:/var/www
environment:
- "DB_PORT=3306" # Port of database container is 3306
- "DB_HOST=database"
networks:
- name_of_network # [2] add container to network
web:
build:
context: ./
dockerfile: web.dockerfile
working_dir: /var/www
volumes:
- ./:/var/www
ports:
- 8080:80
database: # Name of service, which determines hostname of container
image: mysql:5.7
container_name: database
volumes:
- dbdata:/var/lib/mysql
environment:
- "MYSQL_DATABASE=yogadb"
- "MYSQL_USER=yogi"
- "MYSQL_PASSWORD=mypasshere"
- "MYSQL_ROOT_PASSWORD="
ports:
- "33061:3306"
networks:
- name_of_network # [2] add container to network
volumes:
dbdata:
networks:
name_of_network: # [1] create bridged network

Resources