I'm trying to connect a phpmyadmin container to a nginx container with mariadb downloaded.
I can access to phpmyadmin web site, but I can't log in to.
An error code Cannot log in to the MySQL server and mysqli::real_connect(): (HY000/2002): Connection refused will appear.
I made a bridge network "test-net", and connected the phpmyadmin container and the nginx container to the network. I commanded docker run -d --name phpmyadmin -e PMA_HOST=web -e PMA_PORT=3306 -p 8081:80 phpmyadmin/phpmyadmin for the phpmyadmin. Web is the nginx container and 3306 is my mariadb port number.
How can I log in to my database in phpmyadmin?
Related
I want to monitor redis running in webdis docker container.
I use telegraf which collects redis stats but, telegraf is installed on host machine and it cannot connect to redis as it is running inside docker on 6379 port.
I tried to map docker port 6379 on which redis is running inside docker with hosts 6379 port so telegraf can listen to redis metrices, but telegraf cannot listen as connection breaks.
when I use telnet on host, I get connection closed by foreign host error.
telnet 127.0.0.1 6379
Trying 127.0.0.1...
Connected to 127.0.0.1.
Escape character is '^]'.
Connection closed by foreign host.
Also, I am able to connect to webdis port on host machine, which is running on port 7379 inside wedis container.
To start webdis I am using following command : "docker run -d -p 8080:7379 -p 6379:6379 webdis"
Further to debug, I checked that redis inside webdis container is running on interface 127.0.0.1:6379
I checked that it should be running on 0.0.0.0:6379 in-order for port mapping to work properly.
How can I run redis inside webdis image on 0.0.0.0:6379?
Is there any other way I can monitor redis server running inside webdis container?
I tried to start redis-server inside webdis container by binding it to 0.0.0.0 using redis.conf file, but it still binds with 127.0.0.1
To which docker image are you refering. Is it this one? https://github.com/anapsix/docker-webdis/
If yes, when checking the Dockerfile, it does not include redis itself but in docker-compose.yaml there is a redis service include. This one does not expose ports which you need to connect to redis from outside of the container.
You need to change redis service to the following:
...
redis:
image: 'anapsix/redis:latest'
ports:
- '6379:6379'
I have this problem recently ago and I solve it.
webdis.Dockerfile
FROM nicolas/webdis:0.1.19
EXPOSE 6379
EXPOSE 7379
RUN sed -i "s/127.0.0.1/0.0.0.0/g" /etc/redis.conf
docker-compose.yaml
version: "3.8"
services:
webdis:
build:
context: .
dockerfile: webdis.Dockerfile
image: webdis_with_redis_expose
container_name: webdis
restart: unless-stopped
ports:
- "6379:6379"
- "7379:7379"
then execute docker-compose up
How can I run a simple server listening on a port, inside a Docker container?
(In case it matters, this is a MacOS X 10.13.6 host.)
When I run a simple HTTP Server:
python3 -m http.server 8001
the process starts correctly, and it listens correctly on that port (confirmed with telnet localhost 8001).
When I run a Docker container, it also runs the process correctly, but now the connection is refused.
web-api/Dockerfile:
FROM python:3.7
CMD python3 -m http.server 8001
docker-compose.yaml:
version: '3'
services:
web-api:
hostname: web-api
build:
context: ./web-api/
dockerfile: Dockerfile
expose:
- "8001"
ports:
- "8001:8001"
networks:
- api_network
networks:
api_network:
driver: bridge
When i start the container(s), it is running the HTTP server:
$ docker-compose up --detach --build
Building web-api
[…]
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
1db4cd1daaa4 ipsum_web-api "/bin/sh -c 'python3…" 8 minutes ago Up 8 minutes 0.0.0.0:8001->8001/tcp ipsum_web-api_1
$ docker-machine ssh lorem
docker#lorem:~$ ps -ef | grep http.server
root 12883 12829 0 04:40 ? 00:00:00 python3 -m http.server 8001
docker#lorem:~$ telnet localhost 8001
[connects successfully]
^D
docker#lorem:~$ exit
$ telnet localhost 8001
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
telnet: connect to address 127.0.0.1: Connection refused
telnet: Unable to connect to remote host
What is configured incorrectly here, such that the server works inside the Docker container; but I get Connection refused on port 8001 when connecting from outside the container on its exposed port?
Try telnet lorem 8001.
Your python container is exposed to port 8001 on its docker host, which is the one you ssh into (lorem).
When you run docker, docker-compose or docker-machine commands, it uses the value of DOCKER_HOST to figure out which host to connect to. I presume that your DOCKER_HOST has the same ip as lorem.
I have a docker container running this configuration for the gitlab-ce image:
version: "3"
services:
gitlab:
hostname: gitlab.mydomain.com
image: gitlab/gitlab-ce:latest
container_name: gitlab
restart: always
ports:
- 3000:80
volumes:
- /opt/gitlab/config:/etc/gitlab
- /opt/gitlab/logs:/var/log/gitlab
- /opt/gitlab/data:/var/opt/gitlab
networks:
default:
external:
name: custom_network
When running docker ps i see my container up and running with the 80 container port mapped to the 3000 host machine port as intended.
Altough when running : wget -O- https://172.25.0.2:3000 i am getting this error message:
Connecting to 172.25.0.2:3000... failed: Connection refused.
When you map a port, you should use the host IPs to access through the mapped port.
So if you need to access port 80 use the container IP.
If you need to access port 3000 use the host IP or localhost of the main host itself or even if you have a private interface inside your host.
So this command: wget -O- https://172.25.0.2:3000 means that you are talking to the container directly not through the mapped port and requesting a service listening on port 3000 which is not true so the result will be connection refused.
Issue
I cannot connect with MySQL from the host the MariaDB Container is running from. Here are some infos concerning the environment:
docker compose-file
version: '3.1'
services:
db:
image: mariadb
restart: always
environment:
BIND-ADDRESS: 0.0.0.0
MYSQL_ROOT_PASSWORD: example
ports:
- 3306:3006
adminer:
image: adminer
restart: always
ports:
- 8080:8080
Connecting with the container via docker exec -it rancherclientplatform_db_1 /bin/bash and the connecting with mysql -uroot -p unsurprisingly works.
GRANTS
Grants are as follows:
MariaDB [(none)]> SHOW GRANTS;
+----------------------------------------------------------------------------------------------------------------------------------------+
| Grants for root#localhost
|
+----------------------------------------------------------------------------------------------------------------------------------------+
| GRANT ALL PRIVILEGES ON *.* TO 'root'#'localhost' IDENTIFIED BY PASSWORD '*57237BB49761F29AB9724BA084E811D70C12393D' WITH GRANT OPTION |
| GRANT PROXY ON ''#'%' TO 'root'#'localhost' WITH GRANT OPTION
|
+----------------------------------------------------------------------------------------------------------------------------------------+
On the host
No when I try to connect on the host, neither
mysql -uroot -p nor
mysql -hlocalhost -uroot -p nor
mysql -h127.0.0.1 -uroot -p
work. The first 2 fail with a socket error, -h127.0.0.1 fails with
ERROR 2013 (HY000): Lost connection to MySQL server at 'reading initial communication packet', system error: 0 "Internal error/check (Not system error)"
The port 3306 itself seems to be published to the host properly, as
nmap -p3306 localhost delivers
PORT STATE SERVICE
3306/tcp open mysql
Any ideas on what to do here?
MariaDB default port is 3306.
so :
ports:
- 3306:3006
you probably want to map port using 3306:3306 if you want to access mariadb on localhost using port 3306
I have the following setup:
services:
web: &web
ports:
- "3000:3000"
env_file:
- .env.web
links:
- google_service
google_service:
command: bundle exec rails s -b 0.0.0.0 -p 3001
ports:
- "3001:3001"
environment:
RAILS_ENV: development
When I run docker-compose run --publish 3000:3000 web then I can access lvh.me:3001 in my browser.
But when in the container web I try to access this url I get Errno::ECONNREFUSED (Failed to open TCP connection to test.lvh.me:3001 (Connection refused - connect(2) for "127.0.0.1" port 3001)):
How can I access port 3001 from container google_service in the container web? Thanks
As Suggested by Creek, the best way here to call google service container from web container is by addressing google_service:3001.
In networks created via docker compose, the containers know each other by the service names, no matter whether they are linked or not. By default, they are aware about each other.
In case you want to make it accessible via host, use the IP or DNS name of the host machine OR use network mode as host "https://docs.docker.com/compose/compose-file/#network_mode" in docker compose.
While using host network mode, localhost will be the host machine & not the container itself.