docker port command returning nothing - docker

I am following the tutorial here.
In this, you launch a container like so :
docker run --name static-site -e AUTHOR="Your Name" -d -P dockersamples/static-site
e61d12292d69556eabe2a44c16cbd54486b2527e2ce4f95438e504afb7b02810
which I have done. Then it tells you to run the command :
docker port static-site
This is meant to return the ports the container is running on, right ?
It's returning nothing for me. How come ?
sudo docker ps -l shows it has been created.
Thanks a lot.

On MacOS, I have following results:
$ docker run --name static-site -e AUTHOR="Your Name" -d -P dockersamples/static-site
ac25e7cdd81725dfa157ff7027d1ed6beb3839c9457b9627728d700375e7a77f
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
ac25e7cdd817 dockersamples/static-site "/bin/sh -c 'cd /usr…" 6 seconds ago Up 5 seconds 0.0.0.0:32774->80/tcp, 0.0.0.0:32773->443/tcp static-site
$ docker port static-site
443/tcp -> 0.0.0.0:32773
80/tcp -> 0.0.0.0:32774
Please inspect the result of the column 'ports' of the command docker ps on your machine where ports and the mapped ports are also displayed.

Related

"docker run -d-p " return a sha256 code,but "docker ps": nothing,and docker logs :noting

I run in my terminal:
docker run -d -p 8082:80 --name runoob-nginx-test-web -v ~/nginx/www:/usr/share/nginx/html -v ~/nginx/conf/nginx.conf:/etc/nginx/nginx.conf -v ~/nginx/logs:/var/log/nginx matt18/nginx:v1
and get a sha256 code:
072841edf0324c13939e0e95b2119f386414facd124a32de031161f21f498265
but
docker ps : get nothing
docker ps -a : contrainer ID: 072841edf032, STATUS: Exited (0) About a minute ago
docker logs 072841edf032 : get nothing
what is the problem?
would you please check this directory ~/nginx/conf/nginx.conf if it is empty that means nginx service cannot find its config file and exit.

Docker container only lasted for 5 seconds?

So there's tutorial about installing Zenko which uses docker.
At step 5, after starting docker container, I checked its exist by using docker ps and found out it disappeared after few seconds.
Not sure what happened. Some one please help me!
[centos#ip-10-0-7-40 ~]$ docker run -d --rm --name s3server -p 8000:8000 -v /home/centos/.aws/credentials:/root/.aws/credentials -v /home/centos/locationConfig.json:/usr/src/app/locationConfig.json -v /home/centos/config.json:/usr/src/app/config.json -e S3DATA=multiple s3server.custom:1.0
93345a2a3813638bf3bcd984978b7b5ad706b6d15955f0d49269579931d8251d
[centos#ip-10-0-7-40 ~]$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
93345a2a3813 s3server.custom:1.0 “/usr/src/app/docker…” 2 seconds ago Up 2 seconds 0.0.0.0:8000->8000/tcp s3server
[centos#ip-10-0-7-40 ~]$ docker logs 93345a2a3813
Error response from daemon: No such container: 93345a2a3813

Docker CMD to start Haproxy in Dockerfile

Here is my CMD command in my Dockerfile for haproxy:
CMD ["/etc/init.d/haproxy"]
Now when I run the image the following happens:
...
Successfully built 2eb6549e0a22
root#server:/# docker run -d -p 80:80 -p 81:81 -p 443:443 -p 1988:1988 --name haproxy -h haproxy user/haproxy
09b510c4df712414d8855d3e0fb27b7e35d5c5c2f0f9b07f7f29c8efdb93e852
root#server:/# docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
09b510c4df71 user/haproxy "/etc/init.d/haproxy" 5 seconds ago Exited (2) 4 seconds ago haproxy
As you can see it exits straight away. How do I keep it running?
Does your user/haproxy inherit from the haproxy container in the main docker repo? If so the command haproxy should be in the PATH and it includes a -f flag for running it in the foreground.
I usually specify the config file too, so my CMD looks like:
haproxy -d -f /usr/local/etc/haproxy/haproxy.cfg

CKAN Docker container not running

I am running the example installation using docker container from the CKAN site. A clean run, that downloads fresh (no local images) gives no errors
docker run -d --name db ckan/postgresql
docker run -d --name solr ckan/solr
docker run -d -p 80:80 --link db:db --link solr:solr ckan/ckan
but then a "docker ps" does not have the ckan image running ...
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
90c6e6a77b0a ckan/solr:latest "java -jar start.jar 15 minutes ago Up 15 minutes 8983/tcp solr
53f9a9f5c145 ckan/postgresql:latest "/usr/local/bin/run" 20 minutes ago Up 20 minutes 5432/tcp db
Where would errors show?
docker ps only lists running containers. You have to pass in the -a option in order to list all containers you have run
docker ps -a
Find the right container and run the following command to see any error messages it may have reported before shutting down
docker logs <container_id>
As at March 6 2015 described at https://github.com/ckan/ckan/issues/2255
ensure that you have killed off any solr containers still running using
docker rm <idnumber>
then use the more recent schema config
wget https://github.com/ckan/ckan/blob/master/ckan/config/solr/schema.xml
docker run -d --name solr -v `pwd`/schema.xml:/opt/solr/example/solr/ckan/conf/schema.xml ckan/solr
then repeat the original failing step:
docker run -d -p 80:80 --link db:db --link solr:solr ckan/ckan
-- EDIT -- This looks like it works but it introduces other problems.
Am going to experiment with suggestion to use https://github.com/datacats/datacats

How to start a docker container (ubuntu image)

How to stat a docker container. I had created it using
docker run -d -P -v /Users/bsr:/usr/local/users --name test ubuntu
I do have virtual box guest addition installed, and mounting works. But, I am not sure why I can't I keep the shell running.
bsr[~/tmp/web] $ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf620ff6c36a ubuntu:latest "/bin/bash" 2 hours ago Exited (0) 2 minutes ago test
8213c8d49842 nginx:latest "nginx" 3 hours ago Up About an hour 0.0.0.0:49154->80/tcp web
bsr[~/tmp/web] $ docker start test
test
bsr[~/tmp/web] $ docker ps -a
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
cf620ff6c36a ubuntu:latest "/bin/bash" 2 hours ago Exited (0) 2 seconds ago test
8213c8d49842 nginx:latest "nginx" 3 hours ago Up About an hour 0.0.0.0:49154->80/tcp web
bsr[~/tmp/web] $
Edit:
it may be because the command (/bin/bash ??) finishes immediately. When I tried,
docker run -d -P -v /Users/bsr:/usr/local/users --name test5 ubuntu /bin/bash -c "while true; do echo Hello world; sleep 1; done"
I could get the terminal. But isn't there any way to just start a container and get to the terminal ??
If you want to run an interactive process, you should use the -i (keep stdin open in case you detach) and -t (allocate a pseudo-tty) flags:
docker run -it ubuntu
You can look at the docs for more information on those flags and their usage.
You can start by using simple command.
docker run "CONTAINER_ID"

Resources