How to access docker container localhost - docker

I executed docker-compose up and my services worked as well but unfortunately when i hit the url " http://localhost:3000 " it gives me an error I'll paste the docker-compose.yml here.
version: "3.7"
services:
db:
image: postgres
container_name: psql
environment:
POSTGRES_DB: ${DB_DATABASE}
POSTGRES_USER: ${DB_USERNAME}
POSTGRES_PASSWORD: ${DB_PASSWORD}
volumes:
- postgres:/var/lib/postgresql/data
- ./postgresql/conf:/etc/postgresql/
restart: always
ports:
- '5432:5432'
api:
build: .
container_name: api
restart: always
command: yarn start
depends_on:
- db
ports:
- "3000:3000"
volumes:
- .:/usr/app
volumes:
postgres:
When I get into the container and execute curl localhost:3000 it works fine.

My problem was solved after I changed the host in my node api to '0.0.0.0' it was 'localhost' so I think the application was running only inside the container and after that change it was visible from all the created network.

Related

Docker. Phpmyadmin does not see the port assigned to it

I am using the following docker configuration:
version: "3"
services:
database:
image: mysql
ports:
- "3306:3306"
environment:
MYSQL_ROOT_PASSWORD: 1009
restart: "always"
phpmyadmin:
image: phpmyadmin
ports:
- "8080:80"
environment:
PMA_HOST: database
restart: "always"
depends_on:
- database
It works, but if I change the mysql port for my PC to - "3360:3306" (for example 3306 may be busy with the main mysql service running on the computer) - it stops working. If I do this, I will be able to connect to mysql from my computer in CMD like mysql -u root -P 3360 -p, but phpmyadmin will give the error - connection refused.
No matter what I do, I see this error. For example I used the following docker configuration:
version: "3"
services:
database:
image: mysql
networks:
- my-network
ports:
- "3360:3306"
environment:
MYSQL_ROOT_PASSWORD: 1009
restart: "always"
phpmyadmin:
image: phpmyadmin
links:
- database
networks:
- my-network
ports:
- "8080:80"
environment:
PMA_HOST: database
PMA_PORT: 3360
restart: "always"
depends_on:
- database
networks:
my-network:
Even all of this didn't work. Phpmyadmin gave out one inscription when trying to connect - Connection refused all the time. But it still worked in the terminal.
Why can't I use a different port for phpmyadmin in docker?

How to reach localhost services from docker container with IPv4?

I have this docker-compose file where I have a couple of services:
version: "3.8"
services:
app:
container_name: mobile_app_api
env_file:
- .env.development
command: npm run watch:dev
build:
context: .
target: development
dockerfile: ./Dockerfile
restart: always
volumes:
- /usr/src/app/node_modules
- ./:/usr/src/app
depends_on:
- postgres
- redis
extra_hosts:
- host-machine:host-gateway
network_mode: host
redis:
image: "redis:alpine"
container_name: mobile_app_cache
postgres:
image: postgres
container_name: mobile_app_database
restart: "unless-stopped"
environment:
TZ: 'GMT'
PGTZ: 'GMT'
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: mobile_app_database
volumes:
- /:/data/postgres
network_mode: host
Api is supposed to work on localhost:3333, but when I start this with docker-compose up --build in terminal I get this:
mobile_app_api | server running on http://[::1]:3333
And here is 2 things.
Why does it work on IPv6?
How can I change host and make it work on localhost?
PS. My computer is MacOS, but in settings I have turned off IPv6.
I was trying to use host.docker.internal (and gateway.docker.internal) in my compose file, but it didn't work:
extra_hosts:
- host.docker.internal:host-gateway

Docker-compose containers refuse connection

I',m trying to create e simple python-flask api connected to a postgress database,
So added to my docker-compose.yaml my api, db and pgadmin but when I try to start my docker-composer container it doens't
Here is my docker-compose.yaml
version: '3.7'
services:
api:
build: ./Backend/src
depends_on:
- db
environment:
STAGE: test
SQLALCHEMY_DATABASE_URI: postgresql+psycopg2://test:test#db/test
networks:
- default
ports:
- 5000:5000
volumes:
- ./app:/usr/src/app/app
restart: always
db:
environment:
POSTGRES_USER: test
POSTGRES_PASSWORD: test
POSTGRES_DB: test
image: postgres:latest
networks:
- local
ports:
- 5432:5432
restart: always
volumes:
- ./postgres-data:/var/lib/postgresql
pgadmin:
container_name: pgadmin
image: dpage/pgadmin4
environment:
PGADMIN_DEFAULT_EMAIL: admim
PGADMIN_DEFAULT_PASSWORD: admin
ports:
- 5050:80
networks:
- local
restart: always
networks:
local:
driver: bridge
Running the docker from pycharm I get this error:
Deploying 'Compose: docker-compose-dev.yaml'...
Failed to deploy 'Compose: docker-compose-dev.yaml': Sorry but parent: com.intellij.execution.impl.ConsoleViewImpl[,0,0,1008x155,invalid,layout=java.awt.BorderLayout,alignmentX=0.0,alignmentY=0.0,border=,flags=9,maximumSize=,minimumSize=,preferredSize=] has already been disposed (see the cause for stacktrace) so the child: com.intellij.util.Alarm#56e3f4b will never be disposed

How can I call from my frontend docker nginx to my backend in nodeJs docker with docker swarmn

I have 3 containers that I communicate with docker swarm, if I run my application with http and connect as http //domain.com everything works fine, but if I use https ( //www.domain.com) I can't communicate my frontend with the backend and I get the following error:
Ajax.js: 10 POST https //www.domain.com/Init net :: ERR_NAME_NOT_RESOLVED
can someone help me solve my problem
and understand the mistake
Thank you
I leave my compose
version: '3'
services:
ssl:
image: danieldent/nginx-ssl-proxy
restart: always
environment:
UPSTREAM: myApp:8086
SERVERNAME: dominio.com
ports:
- 80:80/tcp
- 443:443/tcp
depends_on:
- myApp
volumes:
- ./nginxAPP:/etc/letsencrypt
- ./nginxAPP:/etc/nginx/user.conf.d:ro
bdd:
restart: always
image: postgres:12
ports:
- 5432:5432/tcp
environment:
POSTGRES_USER: user
POSTGRES_PASSWORD: 12345
POSTGRES_DB: miBDD
volumes:
- ./pgdata:/var/lib/postgresql/data
pgadmin:
image: dpage/pgadmin4
ports:
- 9095:80/tcp
environment:
PGADMIN_DEFAULT_EMAIL: user
PGADMIN_DEFAULT_PASSWORD: 12345
PROXY_X_FOR_COUNT: 3
PROXY_X_PROTO_COUNT: 3
PROXY_X_HOST_COUNT: 3
PROXY_X_PORT_COUNT: 3
volumes:
- ./pgadminAplicattion:/var/lib/pgadmin
myApp:
restart: always
image: appImage
ports:
- 8086:8086
depends_on:
- bdd
working_dir: /usr/myApp
environment:
CONFIG_PATH: ../configuation
command: "node server.js"

Can't access docker container over public ip

So I am creating an application that is running in a docker container on port 3000 of my local machine. I can open the app at localhost:3000, I can also open it on another device but on the same network by using 192.168.68.100:3000. However, I can't access the app by visiting my_public_ip:3000. I added port forwarding on my router for port 3000. I am running the app using docker-compose up and this is my docker-compose file:
version: '3.7'
services:
main:
container_name: main
build:
context: .
target: development
volumes:
- .:/usr/src/app
- /usr/src/app/node_modules
ports:
- 3000:3000
command: npm run start:dev
env_file:
- .env
networks:
- webnet
depends_on:
- db
db:
container_name: db
image: mysql
command: --default-authentication-plugin=mysql_native_password
restart: always
environment:
MYSQL_DATABASE: "..."
MYSQL_USER: "..."
MYSQL_PASSWORD: "..."
MYSQL_ROOT_PASSWORD: "..."
adminer:
container_name: adminer
image: adminer
restart: always
ports:
- 8080:8080
networks:
webnet:
Any suggestions what am I missing?

Resources