3

I have been trying to connect to a docker container via ip, but reamins unsuccessful. When I used "docker inspect container-id" I get this result.

Docker container port

My virtual box settings are by default:

Virtual box settings

Can someone help me resolving this issue?

2
  • When you ran docker, did you use the -p <port number> parameter to make that port available (or use expose in the Dockerfile)? Commented Jul 23, 2014 at 13:15
  • No, I din't. Can you tell me how to run the same container with p parameter? Commented Jul 23, 2014 at 13:17

2 Answers 2

9

When running docker, you can specify which port(s) you'd like to be accessible to the outside world. Basic syntax is:

docker run -p hostPort:containerPort imageName 

or just

docker run -p hostPort imageName 

In the first case, externally, hostPort will be used, but inside the container: containerPort will be used. In the second instance, you'd just be using that port both inside and outside your container.

You can also create an image with ports exposed by using the EXPOSE command in a Dockerfile.

Sign up to request clarification or add additional context in comments.

4 Comments

I commit the container, stopped it, and then run the latest image by using docker run -p 2375 imageName, but still no result...
Does docker inspect new_container_id show the same thing?
Here you are specifying the image name, what if we have a container with modification and data in the database, and we want to expose a certain port on that container.
@Bionix1441: You can't easily do that, but there are some workarounds. Here is one
2

You need to perform port forwarding or just simply expose port.

Port Forwarding:

docker run -p 2022:22 -p 2375:2375

Expose Port:

docker run -p 22 -p 2375

2 Comments

Thanks for your help. I ran these commands but nothing happened.
Image name is missing in the command

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.