when i run docker ps i am seeing port 80 unmapped on the apphub-ui container, i am expecting it to be mapped to 4200, which i also see. I dont understand why 80/tcp is present, it is creating connection refused issues in my app.
Here is the docker ps output
docker ps 10s +59%
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
22cb2b9c28d4 swimlane/apphub-ui:latest "/usr/bin/reefer -t …" 20 seconds ago Up 17 seconds 80/tcp, 0.0.0.0:80->4200/tcp apphub_apphub-ui_1
19a78f93bfe7 swimlane/apphub-api:latest "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 0.0.0.0:3000->3000/tcp apphub_apphub-api_1
7b3478e2dcd5 mongo:3.6 "docker-entrypoint.s…" 4 minutes ago Up 4 minutes 0.0.0.0:27017->27017/tcp apphub_mongo_1
My docker-compose file is as follows
version: '3.6'
volumes:
mongo:
services:
mongo:
image: mongo:3.6
ports:
- 27017:27017
volumes:
- mongo:/data/db
apphub-api:
image: swimlane/apphub-api:latest
ports:
- 3000:3000
depends_on:
- mongo
apphub-ui:
image: swimlane/apphub-ui:latest
ports:
- 80:4200
depends_on:
- apphub-api
environment:
- APPHUB_API_HOST=apphub-api
My app runs fine if i change the mapped ports for the ui feature to 4200:4200, and i dont see the stray unmapped 80
I'm having the feeling that you want to map the port 4200 on your host to the port 80 of your container. If that's the case, you should switch the values. i.e.
ports:
- 4200:80
Related
Basically I'm trying to setup a environment with elasticsearch and kibana with docker on a m1 mac. I've setup the de env variable DOCKER_DEFAULT_PLATFORMto linux/amd64. Everything seems fine on running the container but when I try to connect kibana to elastic they just can't see each other. This is my current docker-composer file:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.3.3-amd64
environment:
- discovery.type=single-node
- node.name=elasticsearch1
- cluster.name=docker-cluster
- cluster.initial_master_nodes=elasticsearch1
- bootstrap.memory_lock=true
- "ES_JAVA_OPTS=-Xms128M -Xmx128M"
ports:
- 9200:9200
networks:
- my-network
kibana:
image: docker.elastic.co/kibana/kibana:8.3.3-amd64
environment:
SERVER_NAME: localhost
ELASTICSEARCH_URL: http://localhost:9200/
ports:
- 5601:5601
depends_on:
- elasticsearch
networks:
- my-network
Before that I was using links insted of networks, no luck with that either. From my terminal or browser I can see both elastic and kibana running on their respective ports. I'm without ideas here, appreciate any help!
EDIT
docker ps output
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
265023669cfd docker.elastic.co/kibana/kibana:8.3.3-amd64 "/bin/tini -- /usr/l…" 14 minutes ago Up 14 minutes 0.0.0.0:5601->5601/tcp folha3_kibana_1
48ee37663dda docker.elastic.co/elasticsearch/elasticsearch:8.3.3-amd64 "/bin/tini -- /usr/l…" 14 minutes ago Up 14 minutes 0.0.0.0:9200->9200/tcp, 9300/tcp folha3_elasticsearch_1
6b1f6dd9473f redis "docker-entrypoint.s…" 14 minutes ago Up 14 minutes 0.0.0.0:6379->6379/tcp folha3_redis_1
2a3ade65634a mysql:5.7 "docker-entrypoint.s…" 14 minutes ago Up 14 minutes 0.0.0.0:3306->3306/tcp, 33060/tcp folha3_mysql_1
ELASTICSEARCH_URL: http://localhost:9200/ should be http://my-network:9200/, localhost can't access elasticsearch container.
I have a bunch of containers running on my ubuntu laptop.As you can see below, I should be able to type in localhost:8080 in the browser and get some response. Instead I get
ERR_CONNECTION_REFUSED
Any idea why?
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
143fbe3867e3 richb201/apache-with-code:latest "/app-entrypoint.sh …" 19 hours ago Up 19 hours 8080/tcp, 0.0.0.0:8000->8000/tcp, 8443/tcp sub_crud_webserver_1
0c2048ef273e bitnami/mariadb:latest "/entrypoint.sh /run…" 21 hours ago Up 21 hours 3306/tcp sub_crud_mariadb_1
fb30f99f037b bitnami/php-fpm:latest "php-fpm -F --pid /o…" 2 days ago Up 19 hours 9000/tcp html_php-fpm_1
be5155202f43 bitnami/mariadb:latest "/entrypoint.sh /run…" 2 days ago Up 19 hours 3306/tcp html_mariadb_1
docker-compose.yml
version: '3'
services:
webserver:
image: richb201/apache-with-code:latest
ports:
- '8000:8000'
volumes:
- /sub_crud:/var/www/html/sub_crud
environment:
XDEBUG_CONFIG: remote_host='richb201-XPS-13-9370'
mariadb:
image: bitnami/mariadb:latest
environment:
- ALLOW_EMPTY_PASSWORD=yes
volumes:
- mariadb-data:/bitnami
php-fpm:
image: bitnami/php-fpm:latest
volumes:
- /sub_crud:/var/www/html/sub_crud
volumes:
According to your docker-compose that you mentioned in a comment (better put this into your question though) you map port 8000 to port 8000. Hence, any requests going to port 8000 on your local machine are received from port 8000 within your container.
If you want to use port 8080 you have to adapt the docker-compose file accordingly, i.e., 8080:8080. Note here that I assume that the apache server in your richb201/apache-with-code image is running on port 8080.
I'm using this docker-compose config for running a classic nodejs app + mysql + redis:
version: '3'
services:
app:
container_name: app
restart: always
build:
context: ./app/
depends_on:
- db
- redis
- elasticsearch
links:
- db
- redis
- elasticsearch
ports:
- "127.0.0.1:${APP_PORT}:${APP_PORT}"
environment:
- "PORT=${APP_PORT}"
- "MYSQL_PORT=${MYSQL_PORT}"
- "REDIS_PORT=${REDIS_PORT}"
redis:
container_name: redis
image: "redis:3-alpine"
restart: always
ports:
- "127.0.0.1:${REDIS_PORT}:6379"
db:
container_name: db
image: mariadb:10.0.30
restart: always
volumes:
- "${MYSQL_DATA_LOCATION}/data:/var/lib/mysql:delegated"
- "${MYSQL_DATA_LOCATION}/my.cnf:/etc/mysql/my.cnf:ro"
ports:
- "127.0.0.1:${MYSQL_PORT}:3306"
environment:
- "MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}"
- "MYSQL_USER=${MYSQL_USER}"
- "MYSQL_PASSWORD=${MYSQL_PASSWORD}"
- "MYSQL_DATABASE=${MYSQL_DATABASE}"
I'm also using a .env file containing the following values:
APP_PORT=5000
MYSQL_PORT=3306
REDIS_PORT=6379
And I start the application with
docker-compose up -d
Everything runs fine this way. I can change the mysql port without error, but if I change the redis port to something else than the original port, I have the following error in the app, when I use this config:
redis.createClient({host: 'redis', port: process.env.REDIS_PORT });
I get the following message:
Error: Redis connection to redis:5555 failed - connect ECONNREFUSED 172.18.0.3:5555
Whereas the connection between the db and the app works correctly :s
In docker ps I can see that the machine started with the expected config:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9c594c6d98b8 nginx:mainline-alpine "nginx -g 'daemon of…" 33 seconds ago Up 39 seconds 0.0.0.0:2000->80/tcp webproxy
62d1f917d7ff app "npm run docker-debug" 36 seconds ago Up 42 seconds 127.0.0.1:5000->5000/tcp, 127.0.0.1:9222->9222/tcp app
7c982d543a7d mariadb:10.0.30 "docker-entrypoint.s…" 39 seconds ago Up 45 seconds 127.0.0.1:4000->3306/tcp db
9dd13967b37d redis:3 "docker-entrypoint.s…" 39 seconds ago Up 44 seconds 127.0.0.1:5555->6379/tcp redis
I can see here that the db is mapped from 4000 to 3306, which works, but the redis mapping from 5555 to 6379 is ignored. And if I manually change the port in the app connection to port 6379, it does work...
Is there something missing in my configuration ?
the redis is running inside the container on port 6379 period (if you dont change the port in its config). On your host you map port 5555 to redis container 6379. All services in docker-compose are visible to each other and you dont even need to EXPOSE those ports to host. In your app settings if you access the redis by redis://redis:6379 will work or with the exposed port redis://HOST_IP:5555 will work too
I'm trying to dockerize a Python application, for which I've been following this tutorial. The tutorial is from April 2015 and still uses Docker Machine, which, judging from this answer, is no longer necessary to run Docker containers locally on Windows.
I got it working with Docker Machine before, and was able to see the web app and interact with it. But now I'm trying to get this working without Docker Machine, with Docker version 17.06.0-ce, build 02c1d87, on Windows 10.
Here's the docker-compose.yml:
web:
restart: always
build: ./web
expose:
- "8000"
links:
- postgres:postgres
volumes:
- /usr/src/app/static
env_file: .env
command: /usr/local/bin/gunicorn -w 2 -b :8000 app:app
nginx:
restart: always
build: ./nginx/
ports:
- "80:80"
volumes:
- /www/static
volumes_from:
- web
links:
- web:web
data:
image: postgres:latest
volumes:
- /var/lib/postgresql
command: "true"
postgres:
restart: always
image: postgres:latest
volumes_from:
- data
ports:
- "5432:5432"
I started the containers:
$ docker-compose up -d
Creating polly_data_1 ...
Creating polly_data_1 ... done
Creating polly_postgres_1 ...
Creating polly_postgres_1 ... done
Creating polly_web_1 ...
Creating polly_web_1 ... done
Creating polly_nginx_1 ...
Creating polly_nginx_1 ... done
Then, when I run docker ps, it shows the following three containers running:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9b2c1048f3a5 polly_nginx "/usr/sbin/nginx" 4 seconds ago Up 3 seconds 0.0.0.0:80->80/tcp polly_nginx_1
d561ac5b901a polly_web "/usr/local/bin/gu..." 5 seconds ago Up 4 seconds 8000/tcp polly_web_1
ecb029d6ec3a postgres:latest "docker-entrypoint..." 7 seconds ago Up 5 seconds 0.0.0.0:5432->5432/tcp polly_postgres_1
(At this point, navigating to http://localhost:8000/ in Chrome already yields ERR_CONNECTION_REFUSED.)
I then ran the script to set up the database, as per the tutorial (extra //s because I'm using Git Bash on Windows 10):
$ docker-compose run web ///usr/local/bin/python create_db.py
Starting polly_data_1 ...
Starting polly_data_1 ... done
Starting polly_postgres_1 ... done
Now when I run docker ps, it shows the following four containers running:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
a129c12f5982 polly_web "//usr/local/bin/p..." 5 seconds ago Up Less than a second 8000/tcp polly_web_run_1
9b2c1048f3a5 polly_nginx "/usr/sbin/nginx" 16 seconds ago Up 15 seconds 0.0.0.0:80->80/tcp polly_nginx_1
d561ac5b901a polly_web "/usr/local/bin/gu..." 17 seconds ago Up 16 seconds 8000/tcp polly_web_1
ecb029d6ec3a postgres:latest "docker-entrypoint..." 19 seconds ago Up 17 seconds 0.0.0.0:5432->5432/tcp polly_postgres_1
And localhost:8000 is still refusing to connect. The web container exposes port 8000, so I don't get why I can't connect to it.
How can I get this working so I can access the web app in the web container locally?
Just change:
expose:
- "8000"
By
ports:
- "8000:8000"
Btw http://localhost:80 is not working?
Regards
Turns out, as suggested by Carlos and 200_OK as part of their answers and comments, it was working as intended - it was running at port 80, not 8000.
Web exposes port 8000 internally inside the container. But that port is not mapped to your host machine port.
I think the problem is in your command. The option is -p, not -b.
web:
restart: always
build: ./web
expose:
- "8000"
links:
- postgres:postgres
volumes:
- /usr/src/app/static
env_file: .env
command: /usr/local/bin/gunicorn -w 2 -p :8000 app:app
I have below YAML file :
seleniumhub:
image: selenium/hub
ports:
- 4444:4444
firefoxnode:
image: selenium/node-firefox-debug
ports:
- 4577
links:
- seleniumhub:hub
expose:
- "5900"
chromenode:
image : selenium/node-chrome-debug
ports:
- 4578
links:
- seleniumhub:hub
expose:
- "5900"
docker ps:
time="2017-04-01T17:57:44+03:00" level=info msg="Unable to use system certificate pool: crypto/x509: system root pool is not available on Windows"
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
9d2ccb193b54 selenium/node-firefox-debug "/opt/bin/entry_po..." 6 seconds ago Up 5 seconds 5900/tcp, 0.0.0.0:32785->4577/tcp dockercompose_firefoxnode_1
4be6223fe043 selenium/node-chrome-debug "/opt/bin/entry_po..." 6 seconds ago Up 5 seconds 5900/tcp, 0.0.0.0:32784->4578/tcp dockercompose_chromenode_1
7d95d3e73016 selenium/hub "/opt/bin/entry_po..." 7 seconds ago Up 6 seconds 0.0.0.0:4444->4444/tcp dockercompose_seleniumhub_1
But whenever I run below command in Docker quick start terminal:
docker port 9d2ccb193b54 5900
I got below:
Error: No public port '5900/tcp' published for 9d2ccb193b54
and I'm not able to connect to the node machines through VNC
for firefoxnode try this configuration:
image: selenium/node-firefox-debug
ports:
- 4577
- 5900
links:
- seleniumhub:hub
expose:
- "5900"
expose does not publish port to the host machine and only accessible to linked services. It works for inter-container communication. ports will expose that port to host machine.
For exposing ports the syntax is:
ports:
- "host:container"
In your case:
image: selenium/node-firefox-debug
ports:
- 4577
- "5900:5900"
links:
- seleniumhub:hub