Instead of using ddev share, I want to run ddev applications on a virtual server (Hetzner, Ubuntu installed, pre-installed docker ce).
As docker already reserved port 80:
Is there a way to forward a specific ddev port to the same port listening to docker?
tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 1650/docker-proxy
My ddev test application is configured to port 8080 and is accessible.
The ddev configuration:
router_http_port: "80"
router_https_port: "443"
host_webserver_port: "8080"
If I change to
router_http_port: "80"
router_https_port: "443"
host_webserver_port: "80"
I'm (of course) running into
Failed to start test: Unable to listen on required ports, port 80 is already in use
Can this conflict be solved by forwarding a port (ddev router) or do I need to change the docker port?
Docker itself does not use ports 80 or 443, so you have something else running there (the most common offender is going to be apache). The docs at https://ddev.readthedocs.io/en/latest/users/troubleshooting/#webserver-ports-are-already-occupied-by-another-webserver explain how to debug this. Since it says docker-proxy is running there, it probably means that you have a docker container already running and bound to port 80.
Try these things:
ddev poweroff (to make sure all ddev things are stopped)
docker ps -a will show you other containers that may be running
docker rm -f $(docker ps -aq) will stop all running containers.
I think when you do these things you'll find docker not listening any more; now you just have to find out why it was listening.
As you already know, the docs for various kinds of sharing are at https://ddev.readthedocs.io/en/latest/users/topics/sharing/ and you may also be interested in the general on-server approaches in https://ddev.readthedocs.io/en/latest/users/alternate-uses/#casual-project-webhosting-on-the-internet-including-lets-encrypt
Related
I have installed docker desktop on my macOS, now it's running in port 8000, how can I change to another port? because I want to use the 8000 port in another application. thanks
Docker Desktop for MAC itself does not run on a port.
It's a container running on a port.
The container has an internal port (within the container) and you can map that to a port on the host.
Mapping is done with "ports" on docker-compose.
For example, the file below has port 3011 internally on the Container, and this is mapped to 80 on the host
version: "3.9"
services:
web:
build: .
container_name: "Web"
env_file:
- env.settings
ports:
- "8080:3011"
(This script is missing a Dockerfile obviously. Let me know if you want a full working example)
Suppose this is running a simple NodeJS/Express Webserver.
If you are in the container, then access that Webserver on port 3011.
But on your host the Webserver is accessed on port 8080.
When I run ddev start, I get the following error in the command line:
Failed to start amdocs-stage: Unable to listen on required ports, port 443 is already in use,
Troubleshooting suggestions at https://ddev.readthedocs.io/en/stable/users/troubleshooting/#unable-listen
I went to my configuration file, replaced port 443 for 8443, and port 80 for 8000. However after I run ddev restart, I still see the same error. All instructed here
I don't have lando, and stopped all the services running through brew.
My Docker desktop is running, and the config.yaml inside .ddev looks like this:
name: cohesion-test
type: drupal8
docroot: web
php_version: "7.4"
webserver_type: nginx-fpm
router_http_port: "8000"
router_https_port: "8443"
xdebug_enabled: false
additional_hostnames: []
additional_fqdns: []
mariadb_version: "10.3"
mysql_version: ""
use_dns_when_possible: true
composer_version: ""
web_environment: []
How can I fix this?
You probably have more than one project active (or perhaps "paused") and the other projects still use port 443 (router_https_port is not a global setting). Do a ddev poweroff to stop all projects and then ddev start. If that doesn't do it, remove any additional containers that ddev may not know about with docker rm -f $(docker ps -aq).
You also may want to look at https://github.com/drud/ddev/issues/2981, which explains that there is a bug in current Docker Desktop for Mac v3.3.3, which regularly creates problems with port access that require ddev poweroff and a docker restart.
I'm beginning to use Docker and following the tutorial (https://docs.docker.com/get-started/part2/) and I am stuck at this point:
docker run --publish 8000:8080 --detach --name bb bulletinboard:1.0
When I try to reach localhost:8080 it says "impossible to reach the site".
When I run docker-machine ip and visiting http://192.168.99.100:8080 with a web client, it does not work.
Please access with port 8000 like localhost:8000 because you mapping docker port from 8080 to 8000 to access from outsaide docker container
Change Port from 8080 to 8000 like this http://192.168.99.100:8000 because you connect machine port 8000 to docker port 8080.
I hope it may help you.
When you use docker commands, always remember..
outside_world -> docker_world
In your 8000:8080 means. You open your container to outside world on port 8000 , inside docker its 8080
Or simply mapping docker port 8080 to 8000 outside.
In this configuration, you should use localhost:8000
docker-machine ip this is completely different network, thats why you can not access it. Its container network.
I am reading the docs here and I find myself a bit confused, since running
docker run --name some-mysql -p 3306:3306 -d mysql
or
docker run --name some-mysql -p 127.0.0.1:3306:3306 -d mysql
then mysql --host localhost --port 3306 -u root gives me the following error :
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2).
But running mysql -u root -p --host 0.0.0.0 works.
Does someone have an explanation ?
With docker port forwarding, there are two network namespaces you need to keep track of. The first is inside your container. If you listen on localhost inside the container, nothing outside the container can connect to your application. That includes blocking port forwarding from the docker host and container-to-container networking. So unless your container is talking to itself, you always listen on 0.0.0.0 with the application you are running inside the container.
The second network namespace is on your docker host. When you forward a port with docker run -p 127.0.0.1:1234:5678 ... that configures a listener on the docker host interface 127.0.0.1 port 1234, and forwards it to the container namespace port 5678 (that container must be listening on 0.0.0.0). If you leave off the ip, docker will publish the port on all interfaces on the host.
So when you configure mysql to listen on 127.0.0.1, there's no way to reach it from outside of the container's networking namespace. If you need to prevent others outside of your docker host from reaching the port, configure that restriction when publishing the port on the docker run cli.
As described in the mysql documentation (https://dev.mysql.com/doc/refman/5.7/en/connecting.html), when you connect to 127.0.0.1 with the client, it'll try to use the unix sockets to perform this operation. Normally this would work fine since it's on the same host. In Docker the socket file is not available.
In my current job we have development environment made with docker-compose.
One container is nginx, which provide routing to other containers.
Everything seems fine and work to my colleague on windows and osx. But on my system (osx El Capitan), there is problem with accessing nginx container on port 80.
There is setup of container from docker-compose.yml
nginx:
build: ./dockerbuild/nginx
ports:
- 80:80
links:
- php
volumes_from:
- app
... and more
In ./dockerbuild/nginx there is nothing special, just nginx config as we know it from everywhere.
When I run everyting with docker-compose create and docker-compose start. Then docker ps give me
3b296c1e4775 docker_nginx "nginx -g 'daemon off" About an hour ago Up 47 minutes 0.0.0.0:80->80/tcp, 443/tcp docker_nginx_1
But when I try to access it for example via curl I get error. curl: (7) Failed to connect to localhost port 80: Connection refused
I try to run container with port 81 and everything works fine.
Port is really binded to docker
22:47 $ sudo lsof -i -n -P | grep TCP
...
com.docke 14718 schovi 38u IPv4 0x6e9c93c51ec4b617 0t0 TCP *:80 (LISTEN)
...
Firewall in osx is turned off and I have no other security.
if you are using docker-for-mac:
Accessing by localhost:80 is correct, though you still have to ensure you do not have a local apache/nginx service running. Often leftovers from boxen/homebrew exist binding that port, because thats what developers did back then :)
if you are using dockertoolbox/virtualbox/whatever hypervisor
You will not be able to access it by localhost, by by the docker-machine ip, so write docker-machine ip default and the use http://$ip:80 in your browser
if that does not help
Ensure your nginx container actually does work, so connect to the container: docker exec -i -t <containerid> bash
and then run ps aux nginx or if telnet is installed try to connect to localhost
Solved!
Problem was, that long long time ago I installed pow (super simple automated rails server which run application on app_name.local domain). And this beast left LaunchAgent script which update pf to forward port 80 to pow port.
In my current job we have development environment made with docker-compose.
A privilege to use.
[W]hen I try to access [nginx on port 80] for example via curl I get error.
Given there's nothing from causing you from accessing docker on your host os you should look at the app running inside the container to ensure it's binding to the correct host, e.g. 0.0.0.0 and not localhost.
For example, if you're running Nuxt inside a container with nuxt-ts observe Nuxt will default to localhost thereby causing the container not to connect to the docker network whereas npx nuxt-ts -H 0.0.0.0 gets things squared away with the container's internal server connecting to the ip of the docker network used (verify ip like docker container inspect d8af01990363).