Docker port uncertainty - docker

I am trying to access a running app on a port that I defined using "EXPOSE".
Here is what I get:
docker#boot2docker:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS
NAMES
653d8ee23260 nginx:latest "nginx -g 'daemon of 2 minutes ago Up 2 minutes 80/tcp, 443/tcp
insane_thompson
007cfcd0f539 highlighter:latest "java -jar -Xmx1500m 8 minutes ago Up 8 minutes 7777/tcp
elated_kirch
docker#boot2docker:~$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
653d8ee23260 nginx:latest "nginx -g 'daemon of 2 minutes ago Up 2 minutes 80/tcp, 443/tcp insane_thompson
007cfcd0f539 highlighter:latest "java -jar -Xmx1500m 8 minutes ago Up 8 minutes 7777/tcp elated_kirch
docker#boot2docker:~$ docker port 007cfcd0f539
docker#boot2docker:~$ docker port 653d8ee23260
docker#boot2docker:~$ docker port 653d8ee23260 80
FATA[0000] Error: No public port '80/tcp' published for 653d8ee23260
docker#boot2docker:~$ docker port 007cfcd0f539 7777
FATA[0000] Error: No public port '7777/tcp' published for 007cfcd0f539
Am I misunderstanding how the "port" command works?

EXPOSE in Dockerfile is not enough.
You need to specifically tell docker to expose port upon docker run with the -P/-p flags.
A much more detailed answer can be found here.

Related

Why can't I go to localhost using Laradock?

I'm getting error: This page isn’t working
I ran the following command inside the Laradock directory yet it's not connecting when I go to localhost. docker-compose up -d nginx postgres
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
19433b191832 laradock_nginx "/bin/bash /opt/star…" 5 minutes ago Up 5 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:443->443/tcp laradock_nginx_1
e7f68a9d841d laradock_php-fpm "docker-php-entrypoi…" 5 minutes ago Up 5 minutes 9000/tcp laradock_php-fpm_1
3c73fedff4aa laradock_workspace "/sbin/my_init" 5 minutes ago Up 5 minutes 0.0.0.0:2222->22/tcp laradock_workspace_1
eefb58598ee5 laradock_postgres "docker-entrypoint.s…" 5 minutes ago Up 5 minutes 0.0.0.0:5432->5432/tcp laradock_postgres_1
ea559a775854 docker:dind "dockerd-entrypoint.…" 5 minutes ago Up 5 minutes 2375/tcp laradock_docker-in-docker_1
docker-compose ps returns these results:
$ docker-compose ps
Name Command State Ports
--------------------------------------------------------------------------------------------------------------
laradock_docker-in-docker_1 dockerd-entrypoint.sh Up 2375/tcp
laradock_nginx_1 /bin/bash /opt/startup.sh Up 0.0.0.0:443->443/tcp, 0.0.0.0:80->80/tcp
laradock_php-fpm_1 docker-php-entrypoint php-fpm Up 9000/tcp
laradock_postgres_1 docker-entrypoint.sh postgres Up 0.0.0.0:5432->5432/tcp
laradock_workspace_1 /sbin/my_init Up 0.0.0.0:2222->22/tcp
Any help would be much appreciated.
I figured this out. I edited my docker-compose file volume to be /local/path/to/default.conf:/etc/nginx/sites-available
This is a problem because nginx looks for default.conf file but the volumes flag was setting sites-available as the file. I thought docker volume would symlink the file into the site-available directory not make it a file.
The correct volume syntax should be:
/local/path/to/default.conf:/etc/nginx/sites-available/default.conf

Is there a way to stop docker swarm leave --force from removing the redirection of port of the current containers running

I have 2 containers running using the ports 5001 and 5000 of my server. This server can be part of a docker swarm. When I leave the docker swarm using Docker swarm leave --force the redirection of my physicals port is gone.
[98-swarm-hello-world *]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dfc9bbc8573b registry "/entrypoint.sh /etc…" 7 seconds ago Up 5 seconds 0.0.0.0:5001->5000/tcp docker-registry_registry-private_1
760cbf6e6b15 registry "/entrypoint.sh /etc…" 7 seconds ago Up 5 seconds 0.0.0.0:5000->5000/tcp docker-registry_registry-mirror_1
[98-swarm-hello-world *]$ docker swarm init
Swarm initialized: current node (srlmoh6a2nm28biifgv7vpjb1) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-1hws6so0lpikgc1e0ztlhpobj7ejvg0hg4lk0k22wsdss4ntri-7l6eoo7cimlhmpzputbjpo6qt 192.168.65.3:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
[98-swarm-hello-world *]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dfc9bbc8573b registry "/entrypoint.sh /etc…" 21 seconds ago Up 19 seconds 0.0.0.0:5001->5000/tcp docker-registry_registry-private_1
760cbf6e6b15 registry "/entrypoint.sh /etc…" 21 seconds ago Up 19 seconds 0.0.0.0:5000->5000/tcp docker-registry_registry-mirror_1
For now the ports are still here but then :
[98-swarm-hello-world *]$ docker swarm leave --force
Node left the swarm.
[98-swarm-hello-world *]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
dfc9bbc8573b registry "/entrypoint.sh /etc…" 33 seconds ago Up 31 seconds docker-registry_registry-private_1
760cbf6e6b15 registry "/entrypoint.sh /etc…" 33 seconds ago Up 31 seconds docker-registry_registry-mirror_1
EDIT : My image might have a problem, with another image (created with docker container run --rm --name nginx -p 80:80 -d nginx) the ports are still exposed :
[root#n0300 docker-registry]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f40e2463eb38 registry "/entrypoint.sh /etc…" 6 seconds ago Up 2 seconds 0.0.0.0:5001->5000/tcp docker-registry_registry-private_1
fbb31476bddf registry "/entrypoint.sh /etc…" 6 seconds ago Up 2 seconds 0.0.0.0:5000->5000/tcp docker-registry_registry-mirror_1
b3086042d2f5 nginx "nginx -g 'daemon of…" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp nginx
[root#n0300 docker-registry]# docker swarm init
Swarm initialized: current node (s5fpahqg1klnbi2w90pver5ao) is now a manager.
To add a worker to this swarm, run the following command:
docker swarm join --token SWMTKN-1-3b2gv5e1f3x4ez9s3itf5hxnilypvh0g4t4butdhggwqpjsx2n-c4l1o42p4fl9mwy8ktjhl3yzo 172.16.1.44:2377
To add a manager to this swarm, run 'docker swarm join-token manager' and follow the instructions.
[root#n0300 docker-registry]# docker swarm leave --fore
unknown flag: --fore
See 'docker swarm leave --help'.
[root#n0300 docker-registry]# docker swarm leave --force
Node left the swarm.
[root#n0300 docker-registry]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f40e2463eb38 registry "/entrypoint.sh /etc…" 22 seconds ago Up 18 seconds docker-registry_registry-private_1
fbb31476bddf registry "/entrypoint.sh /etc…" 22 seconds ago Up 18 seconds docker-registry_registry-mirror_1
b3086042d2f5 nginx "nginx -g 'daemon of…" 3 minutes ago Up 3 minutes 0.0.0.0:80->80/tcp nginx
EDIT 2 : My image isn't build, I'm just running a container.
Here's the compose file:
version: '3'
services:
registry-mirror:
image: registry
environment:
- REGISTRY_HTTP_ADDR=0.0.0.0:5000
volumes:
- ./config-mirror-registry.yml:/etc/docker/registry/config.yml
ports:
- "5000:5000"
registry-private:
image: registry
environment:
- REGISTRY_HTTP_ADDR=0.0.0.0:5000
ports:
- "5001:5000"
and here the config file
version: 0.1
log:
fields:
service: registry
storage:
cache:
blobdescriptor: inmemory
filesystem:
rootdirectory: /var/lib/registry
http:
addr: :5000
headers:
X-Content-Type-Options: [nosniff]
health:
storagedriver:
enabled: true
interval: 10s
threshold: 3
proxy:
remoteurl: https://registry-1.docker.io

Docker Container Not accessible after commit

I just committed a docker container and getting following list
[root#kentuckianatradenew log]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
19d7479f4f66 newsslcyclos "catalina.sh run" 12 minutes ago Up 12 minutes 0.0.0.0:80->80/tcp, 8080/tcp n2n33
88175386c0da cyclos/db "docker-entrypoint.s…" 26 hours ago Up 21 minutes 5432/tcp cyclos-db
But when I browse it through IP it won't accessible while same was fine before commit.
docker port 19d7479f4f66
80/tcp -> 0.0.0.0:80

Ports not accessable

I installed docker and issues a 'docker swarm init' command.
I'm trying to launch a stack using the following command: docker stack deploy -c docker-compose.yml mystack
The docker-compose file can be found here, the first docker file here and the second here
The output of 'docker ps' is:
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
f582b3e8d33e tons/ip2country:latest "/bin/sh -c 'java -D…" 8 seconds ago Up 6 seconds 8080/tcp ip2flag_country-service.1.t5rvuqaw8tj7v20u0xo0dgy6x
bbf2c8304f1a tons/ip2flag:latest "/bin/sh -c 'java -D…" 10 seconds ago Up 8 seconds 8080/tcp ip2flag_app.1.z00gz8adj2yshpgimaw2o55d3
cbc7eaace4bf portainer/portainer "/portainer" 39 minutes ago Up 39 minutes 0.0.0.0:9000->9000/tcp portainer
The output of 'docker service ls' is:
ID NAME MODE REPLICAS IMAGE PORTS
ex51pyh1oyyo ip2flag_app replicated 1/1 tons/ip2flag:latest *:8080->8080/tcp
yhbt97lmjqan ip2flag_country-service replicated 1/1 tons/ip2country:latest
Since I'm running this on localhost I'd expect http://localhost:8080/ to return some sort of data. But it just times out. If I attach to the container and execute something like wget localhost:8080/some/path it works as expected. So the service is running and within the container listening to port 8080. However the port isn't exposed outside of dockers net. Further more I can add that launching with 'docker-compose up' works just fine too. But not with 'docker stack deploy'. Any clue about what I'm doing wrong?

Cannot start Portainer which compose

I don't know why but I cannot start portainer.
I downloaded https://github.com/portainer/portainer-compose
I did a docker-compose up
Everything seems fine:
portainer-proxy
docker ps
CONTAINER ID IMAGE COMMAND CREATED
9c01c18dcc23 portainer/portainer:latest "/portainer --temp..." 5 minutes ago
2de6b22cadb0 portainer_proxy "nginx -g 'daemon ..." 10 minutes ago
1c0166b3f870 v2tec/watchtower "/watchtower --cle..." 10 minutes ago
893a507f62e3 portainer/templates "nginx -g 'daemon ..." 10 minutes ago
And I have this in the logs :
portainer-app | 2017/11/12 15:01:54 Warning: the --templates / -t flag is deprecated and will be removed in future versions.
portainer-app | 2017/11/12 15:01:54 Starting Portainer 1.15.1 on :9000
I should be able to access portainer on port 9000, but nothing happens here.
If I try to access localhost then I have 404 from nginx.
Do you have any idea?
In the doc of the partainer compose, the link to access to partainer is: http://localhost/portainer (replace localhost by the ip of your server if necessary). So it uses the 80 port.
If you need to use the 9000 port, replace this line ine the docker-compose.yml:
ports:
- "80:80"
by
ports:
- "9000:80"
And access to it: http://localhost:9000/portainer
HTH

Resources