Docker cannot access an external SMTP server - docker-compose

I have an SMTP server running on a machine outside my machine. From my machine I can reach this server utilizing ping or telnet on server port, it responds. But from inside docker I cannot reach. I've created my docker using docker-compose an set the network to type bridge.
networks:
app_network_bridge:
driver: bridge
How can I reach from docker an outside server? I've checked with ping and telnet and is not reachable.

Related

How can I connect to a PostgreSQL server running inside a Docker container on a GCP virtual machine?

I have pgAdmin4 and PostgreSQL running inside Docker containers on a GCP virtual machine. I have already ingested data into PostgreSQL and I can access the tables and databases using pgcli. However, I am unable to connect to pgAdmin4. How can I connect to the pgAdmin4?
You will access pgadmin with your browser.
When you start up the pgadmin container, you should have configured a port mapping. Add a firewall rule to your VM's network configuration for this mapped port (for example, I've configured an ingress firewall rule for 15432 because I mapped 15432 to 80 in my docker config).
Example snippet from docker-compose:
ports:
- 15432:80
Assuming you have configured an external IP address, use the external IP address and the port number in your browser to access pgadmin. Like this, where XX.XX.XX.XXX is your external IP and 15432 was mapped to port 80:
http://XX.XX.XX.XXX:15432/login

can't connect mongodb on host from docker container

I have a mongo on my host machine, and an ubuntu container which is also running on my machine. I want that container to connect to mongo.
I set as host url, my host ip from docker network : 172.17.0.1
and in the /etc/mongod.conf file I set the bindIp to 0.0.0.0
from the container, I can ping the host,but the mongo service is not accessible, I get that error :
Connecting to: mongodb://172.17.0.1:27017/directConnection=true&appName=mongosh+1.5.0
MongoServerSelectionError: connection timed out
More over, I can connect from host to the mongo service with that command :
mongosh mongodb://172.17.0.1:27017
Do you know why I can't access mongo service from my container ?
You can use host.docker.internal as reference to your host machine from the container. So mongo host.docker.internal:27017 should work.
From docker documentation:
I want to connect from a container to a service on the host
The host has a changing IP address (or none if you have no network access). We recommend that you connect to the special DNS name host.docker.internal which resolves to the internal IP address used by the host. This is for development purpose and does not work in a production environment outside of Docker Desktop.
On your local machine that has Mongo service is running, you can access by Mongo client because you expose the service at 127.0.0.1:27017.
However, it is not true if standing from your unbuntu container, there is no Mongo service is running at 172.0.0.1:27017 of the ubuntu container.
Docker-compose is the right tool for you to make containers communication to each other.

Docker container, running PostgreSQL not allowing php's pg_connect from another container

I have the following architecture:
A network with 3 containers:
container_db, running PostgreSQL
container_pg_admin, running a simple pgAdmin environment
container_php_dev, running the whole environment, needed for the application to function properly (nginx, php, angular for the frontend, etc.)
When I try to pg_connect() from container_php_dev to container_db the connection gets refused. This is the actual error message I get: pg_connect(): Unable to connect to PostgreSQL server: could not connect to server: No route to host↵ Is the server running on host "container_db" (172.18.0.4) and accepting↵ TCP/IP connections on port 5432?.
However, when I try to connect to container_db from container_pg_admin I face no problem achieving this (host is container_db and port is 5432). Even if I map port 5432 of container_db to 5555 on host, I'm able to connect to 127.0.0.1:5555 from DBeaver or other DB Manager (TeamSQL).
All containers were restarted a few times as well as docker itself. And as this is my development machine, the host PC was restarted as well.
What might be the problem, how to diagnose and possibly solve? Have any of you experienced such strange docker behaviour?
Try running the container_db in the hosted network using flag --network host

Communicate docker container with host in network

Is it possible to send a message with a Socket from inside a docker container to the network of the host that deploys it? I mean...
I have a router with two hosts connected. One of them deploys a docker container with an image that uses a Socket in Python to send UDP multicast messages. The other host in the network executes a program that listens to that multicast address to receive UDP messages (but it doesn't run inside a docker container).
I am trying to run the container with the following command:
docker run --name send-udp-container -p 192.168.0.100:5007:5007/udp udp-image
What I am trying to achieve with this is to map the port 5007 of the host with the port 5007 with the container. So, when the container sends the UDP message to that port, it is broadcasted through 192.168.0.100 IP address (which is the interface I want to use to communicate with the other host).
I know it can be fixed using this command to share the network:
docker run --name send-udp-container --network host udp-image
But I would prefer to avoid sharing the network.
Any Ideas?
Untested:
# create a network and set the gateway
docker network create -d bridge --subnet 192.168.0.0/24 --gateway 192.168.0.1 mynetwork
docker run --net=mynetwork --name send-udp-container udp-image
Now from inside the container, you should be able to reach 192.168.0.100

How to ping to my local machine from AWS EC2 instance?

I have started an ubuntu instance on AWS EC2
e.g. [ec2-user#ip-XXX-XX-XX-XX ~]$
Inside this instance, I am running a socket program for sending the data to my local system.
The program is running properly, but not able to connect to my local IP.
I am trying to ping my local system also from AWS ec2 user, but it is also not working.But I am able to ping google(8.8.8.8).
e.g. [ec2-user#ip-xxx-xx-xx-xx ~]$ ping xxx.xxx.xx.xx(my local IP)
I have set all security groups(inbound), like All Trafic,All TCP and so on.
Sorry for bad English.
Thank You
Your computer (PC) cannot be pinged from an AWS hosted machine
This is probably because the VM on your computer is using NAT outbound to talk to the LAN, which goes to an Internet router, which sends the packets to AWS
The reverse route (inbound to your PC) does not exist so starting a ping echo request from a AWS machine will not work
It is possible to get around this by opening a pass through on your router but generally this is not a great idea
However if you want to make a socket connection securely there is a way
First, start a ssh session with remote port forwarding. In the Linux ssh client this is using the -R option.
For example, if your local system is running a listening service on port 80 and your remote system has the address of 54.10.10.10 then
ssh -R 8080:localhost:80 ec2-user#54.10.10.10
Will establish a circuit such that connections to the "localhost" on the remote ec2 server on port 8080 are connected to the "localhost" on port 80 of your local machine
If you are not using a ssh cli program, most ssh clients have a facility of this sort.
Note that it is necessary to keep the ssh session open to be able to use the connections