简体   繁体   中英

Some questions of Docker -p and Dockerfile

1: docker run -d -p 3000:3000 images

If i up a localhost:3000 server in container,how can i open it in my machine browser, what's the ip? I've tried localhost:3000 or 0.0.0.0:3000 .


2: I use docker pull ubuntu and docker run it, after updating and deploying the server i commmited it.So now i have one ubuntu and a new image.

Next time i run a container using this new image, The shell scripts still needs to be sourced, also the server needs to reopened again.

How can i commit the image that it can source the scripts and deployed by itself when i docker run it.

Thanks.

I don't quite understand questions 2 or 3, can you add more context?

Regarding your question about using -p , you should be able to visit in your browser using http://localhost:3000/ . However that assumes a couple of things are true.

First, you used -p 3000:<container-port> - looks good on this point.

Second, the image you have run exposed port 3000 ( EXPOSE 3000 ).

And third, the service running in the container is listening on 0.0.0.0:3000 . If it is listening on localhost inside the container , then the port export will not work. Each container has its own localhost which is usable only inside the container. So it needs to be listening on all IPs inside the container, in order for outside connections to reach the service from outside of the container.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM