I am having issues with running Adminer on my localhost.
After running this command:
$ docker run --rm -ti --network host adminer
[Sun Jan 10 18:19:33 2021] PHP 7.4.14 Development Server (http://[::]:8080) started
I expect to see Adminer running on localhost:8080, however my browser "can't establish a connection to the server at localhost:8080"
Not sure how to proceed from here. My terminal states that the server is running on 8080
Thank you!
If you have to run docker on a virtual machine then I think it's only listening to port 8080 on that VM (which you could check with wget or curl on the VM IP address which you should be able to find using the docker desktop, or you could use the VM console and try wget or curl on http://localhost:8080)
You may need to use -p 8080:8080 instead of --network hostto expose the port on your local machine.
Related
Yesterday i created a MariaDB image with this command:
docker run --name test_smdb -e MYSQL_ROOT_PASSWORD=<some_password> -p 3306:3306 -d mariadb:10.4.26
And as here is said:
https://docs.docker.com/config/containers/container-networking/
-p 8080:80 Map TCP port 80 in the container to port 8080 on the Docker host.
So i expected to be able to connect to the database via localhost:3306, from a Python application, running in another container in the same Docker instance (deployed on my machine), but this did not happen. I got:
Can't connect to MariaDB : 2003 (HY000): Can't connect to MySQL server on 'localhost:3306' (99)
So after some investigation and following some advices from here:
Docker cannot connect application to MySQL
, executing :
docker network list
docker network inspect <id>
i got the ip of the container and connected to MariaDB, using it.
But i still would like to connect to the MariaDB container, using localhost. How to do that?
I pulled a python docker image using:
docker pull python:3.8
Then I started a simple http server with:
docker run -ti -p 8080:8080 900972ffeecd python -m http.server 8080
If I docker exec into the container and run curl localhost:8080 I get the response I expect, but if I run the same curl command from the host machine it fails.
Shouldn't using -p 8080:8080 be enough to expose the port?
Potentially relevant info: I'm using colima on MacOS.
I hate to admit, but restarting my machine sent the issue away.
I am unable to connect (timeout) to a dockerized redis server1 which was started with the command of:
docker run -it --rm -p 6379:6379 redis:alpine
I've tried to start the server with configs:
set bind to 0.0.0.0
protected-mode no
I am however able to connect to my redis server with another docker container with the following command:
docker run -it --rm redis:alpine redis-cli -h host.docker.internal -p 6379
and also tried configuring the same parameters through cli as well.
When I try to connect the connection times out, I tried with both internal ip
172.17.0.x
and with the internal domain name:
host.docker.internal
to no avail. Further note that I was able to connect to redis server when installed with
brew install redis
on the host.
What am I missing, how can I resolve the issue so that I can connect to redis-server that is within a docker container from the container's host?
Environment details
OS: MacOS Monterey Version: 12.6 (21G115)
Docker version 20.10.17, build 100c701
1 More specifically I've tried with both
rdcli -h host.docker.internal in the mac terminal and also on application side with StackExchange.Redis.
More specifically I've tried with both rdcli -h host.docker.internal in the mac terminal
The host.docker.internal is a DNS name to access the docker host from inside a container. It's a bad practice to use this inside one container to talk to another container. Instead you'd create a network, create both containers in that network, and use the container name to connect. When that's done, the port doesn't even need to be published.
From the host, that's when you connect to the published port. Since the container is deployed with -p 6379:6379, you should be able to access that port from the hostname of your host, or localhost on that host:
rdcli -h localhost
Running docker for Mac 17.06.0 I have created a docker file that creates an image of Apache server. Notice it exposes port 80.
FROM ubuntu:16.04
RUN apt-get update
RUN apt-get install -y apache2
ADD index.html /var/www/html/
CMD /usr/sbin/apache2ctl -D FOREGROUND
EXPOSE 80
In the same folder of the Dockerfile I have created a simple index.httml file.
Then I built and ran it using
docker build -t webserver .
docker run -d webserver
I took the IP address of the running container using
docker inspect [container_name] | grep -i IPAddress
and when I curl
curl 172.17.0.2
I get no answer.
I do get an answer when running -p 80:80 and using localhost in the curl command.
curl localhost
But I want to understand why can't I curl the container IP.
Questions:
How can I get an answer for my curl?
I understand I can't ping my container when using docker for Mac (link).
Can I telnet it just to verify that the port is exposed?
Can I SSH it?
On Docker for Mac the Docker engine is running inside a small VM using Hyper-V. As consequence, the ip 172.17.0.2 is valid only inside that VM and not on your host system. See https://docs.docker.com/docker-for-mac/docker-toolbox/#the-docker-for-mac-environment for more details and comparison to other VM concepts like Docker Machine.
When you run your Docker container, you need to bind a local port to the container like so:
docker run -d -p 80:80 webserver
where the first 80 is the port on the localhost and the second is the port on the container that is exposed. Just having the port exposed in the dockerfile is not enough to access it from the localhost.
I'm unable to access a nodejs based service via http://localhost:8000 running in a docker image. I'm using Docker for Mac (https://docs.docker.com/docker-for-mac/)
I'm following the tutorial here https://nodejs.org/en/docs/guides/nodejs-docker-webapp/.
The server runs on port 8000. I start the docker image with the following:
$ docker run -p 8000:8000 -d geuis/node-server:latest
If I run docker ps I see:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9fa2e446918b geuis/node-server:latest "npm start" 6 seconds ago Up 5 seconds 0.0.0.0:8000->8000/tcp unruffled_lewin
If I docker exec -it 9fa2e446918b /bin/bash I can access the docker vm and I can curl http://localhost:8000 and access the server from inside the container.
However, I try the same curl http://localhost:8000 from my system terminal and its not accessible.
Not sure what I need to do next.
Try the following listen statement:
app.listen(PORT, '0.0.0.0');
From reading the tutorial you mention it looks like express is listening on localhost. This is fine if you're running locally but inside of a container, localhost is not the same localhost that's outside of the container.
0.0.0.0 is the unspecified IPv4 address and so Express will bind on any IP it can find, which will be the IP that your requests are coming in from outside the container.