How to run docker daemon from shell and browser?

I just published an mvc application to a CentOS server at port 2375. So how to run it from the shell and browser?


The image name is “dockerdemo”.


You probably didn’t actually expose that application on port 2375 though, right? That’s the port used for the Docker API, as shown in your CLI screenshot above.

If you want to access ports in containers you need to run the container using -p <hostport>:<containerport> and then access them at <hostip>:<hostport> (or localhost:<hostport> if you’re directly on the host machine).

I can’t see the PORTS column in your docker ps output, so there’s no way to tell you how to access that port.

Hi I run the command ps. Getting the image below.


You haven’t exposed any ports. Use docker run's -p / --publish flag.

It shows nothing.

$ docker run --help

You will see the -p / --publish flag there.

I just checked the help. There is no -p / --port flag. Also there is no -p / --publish as well.

But there is -p / --publish-all, what is run's? I couldn’t find it.

I mis-spoke (it’s not --port), it’s docker run --publish, and I am 100% certain that it exists. Maybe you’re overlooking it?

  -p, --publish=[]                Publish a container's port(s) to the host

There is also -P (note the capitalization) and --publish-all, as you noted:

  -P, --publish-all               Publish all exposed ports to random ports

As for run's, that’s a communication error, not a part of the Docker CLI. Apostrophe (') + s in American English is used to indicate ownership, as in “my brother’s car”, or “my mother’s house”. I was trying to indicate that docker run has a --publish flag: ergo, docker run's --publish flag.

Anyway, -p <hostport>:<containerport> will forward a port from the container (which has its own sandboxed network namespace) to the host localhost. e.g.:

$ docker run -p 8080:8080 foobar
$ curl localhost:8080

Please see my command.

@zhshqzyc No slash, just pick -p or --publish – I was just using it as a visual indicator to choose one or the other.

You want something like

$ docker -H tcp:// run -d -p 8080:8080 dockerdemo

(Substitute your port for 8080)

If you are not that familiar with UNIX command line I suggest picking up a few basics to get a feel for the shell, otherwise Docker CLI will be much harder to use.

I run the command as below:

However when I type the url http://localhost:5000 in the browser.

This site can’t be reached

Use the --publish flag like I’ve suggested above.

I guess that I messed up. I created a container and an image. The port was 5004. So on my Windows desktop, I typed It is running.

I wanted to play around it. So I went to the Linux shell and stopped the container. I tried to start the container but I don’t know whether the image started or not. Anyway the web page is not shown. I am not sure how to play the previous scene again?