I have a container that it has several ports, I want to have access to one of its ports (9001
) outside of this docker as remote.
- My docker IP is:
172.17.0.1
- My container IP is:
172.19.0.23
- My server IP is:
192.168.1.131
I have searched about that and I found expose port
keyword, and I did it but not worked.
How to expose docker ports to make your containers externally accessible
Reference
This is my docker-compose file:
version: '3'
services:
nginx:
image: nginx:latest
container_name: nginx
ports:
- "8010:8010"
volumes:
- .:/code
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf
links:
- ivms
restart: unless-stopped
ivms:
build: .
container_name: ivms
command: bash bashes/createDB.sh
volumes:
- .:/code
expose:
- "8010"
- "9001" # exposed disired port
ports:
- "9001:9001"
I run above docker-compose file with: $ docker-compose up -d
- But when I using
server_IP:9001 --> 192.168.1.131:9001
ordocker_IP:9001 --> 172.17.0.1:9001
can not access to that (in remote or local mode) - But when using
container_IP:9001 --> 172.19.0.23:9001
this works in local.
What should I do that I can access to server_IP:9001 --> 192.168.1.131:9001
?
[NOTE]:
In
createDB.sh
runs several operations such as creating a ZMQ on9001
port.I have been set the port allowing before, using
$ ufw allow 9001
- I tried on Ubuntu 16.04 and Ubuntu-Server 16.04
Any help would be appreciated.
ports:
insteadexpose:
? – Usuallyport: - "9001:9001"
or using9002
instead of9001
usingport: - "9002:9001"
bot not worked. – Garfishports
– Garfishnetwork_mode: host
in docker compose services – UsuallyCannot create container for service ivms: Conflicting options: host type networking can't be used with links. This would result in undefined behavior ERROR: Encountered errors while bringing up the project.
– Garfish