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.
Related
I want to setup and run multiple oracle database docker containers on the same host (Red Hat OS), each database will use a separated area on the host to store data. These docker containers use the same docker image.
For example:
Container 1 will listen on port 1521 and store data in /home/user/oracle_data/container_1 folder on host.
Container 2 will listen on port 1522 and store data in /home/user/oracle_data/container_2 folder on host.
Container 3 will listen on port 1523 and store data in /home/user/oracle_data/container_3 folder on host.
Can you tell me the best practice to solve this task?
Thanks and best regards,
Inside every container keep using the default port of 1521.
Remap this port to external world to your custom port.
Same thing with folders - keep the folders the same inside the container, remap them to different folders in the host
For example, if using docker-compose, for the first container use:
ports:
1521:1521
volumes:
/oracle/data1:/oracle/data
for the second container use:
ports:
1522:1521
volumes:
/oracle/data2:/oracle/data
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
I'm new to Docker and have access an API that runs on a container.
I'm running a container via:
cp -r ./lib app/
docker-compose up -d --build app
rm -fr app/lib/*
In my docker-compose.yml I do have the ports set to:
app:
build: ./app
container_name: my-app
ports:
- "9080:8080"
- "9990:9990"
- "6000:6000"
- "9877:9877"
- "1551:1551"
And a default ip for docker-machine: 192.168.99.100
I should be able to send requests to an api via https://192.168.99.100:8080/restapicall
What am I missing? Is there any way to expose ports to localost in shell script?
Few observations.
You are using wrong port number (8080) to access restapicall, In your docker-compose file, you are exposing port 8080 to 9080 (- "9080:8080").
Why are you using https? have you got SSL certificate set-up? if not try with http.
192.168.99.100 is this docker internal IP address? if yes then use your machine IP address or localhost?
Now try with below URL.
Use localhost if you are running docker on the same machine.
http://localhost:9080/restapicall
Use machine ip address if Docker is running on different machine.
http://machine-ip-address:9080/restapicall
If this doesn't work then please share your Docker file and docker-compose file.
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.
I want to set up redis configuration in docker.
I have my own redis.conf under D:/redis/redis.conf and have configured it to have bind 127.0.0.1 and have uncommented requirepass foobared
Then used this command to load this configuration in docker:
docker run --volume D:/redis/redis.conf:/usr/local/etc/redis/redis.conf --name myredis redis redis-server /usr/local/etc/redis/redis.conf
Next,
I have docker-compose.yml in my application in maven Project under src/resources.
I have the following in my docker-compase.yml
redis:
image: redis
ports:
- "6379:6379"
And i execute the command :
docker-compose up
The Server runs, but when i check with the command:
docker ps -a
it Shows that redis Image runs at 0.0.0.0:6379.
I want it to run at 127.0.0.1.
How do i get that?
isn't my configuration file loading or is it wrong? or my commands are wrong?
Any suggestions are of great help.
PS: I am using Windows.
Thanks
Try to execute:
docker inspect <container_id>
And use "NetworkSettings"->"Gateway" (it must be 172.17.0.1) value instead of 127.0.0.1.
You can't use 127.0.0.1 as your Redis was run in the isolated environment.
Or you can link your containers.
So first of all you should not be worried about redis saying listening on 0.0.0.0:6379. Because redis is running inside the container. And if it doesn't listen on 0.0.0.0 then you won't be able to make any connections.
Next if you want redis to only listen on localhost on localhost then you need to use below
redis:
image: redis
ports:
- "127.0.0.1:6379:6379"
PS: I have not run container or docker for windows with 127.0.0.1 port mapping, so you will have to see if it works. Because host networking in Windows, Mac and Linux are different and may not work this way