chaotic
chaotic

Reputation: 411

Docker Container - ports settings

Can you explain me one thing related to Docker container ports?

Scenario: I've created a new Dockerfile and docker-compose.yml file (https://github.com/fdolsky321/Jenkins_Docker) and I used EXPOSE 49005 as well as I configured both ports in docker-compose.yml to 49005. (is the volume in docker-compose set correctly? I'm using Windows 10 Pro).

Then I just build and push that and in the end, I used docker-compose up... But then I saw, that there are still default ports 8080 and 50000, can you explain me, how is possible, that there are ocuring still these ports, which I don't want to use?

Then I'm trying to run this image, but I'm not able to open jenkins on any port (8080, 50000, 49005). It's working pretty well, when I'm using docker run command, but I would like to use the ports used in docker-compose.yml file.

Can you give any advice, how ports work in docker?

https://i.sstatic.net/yFW1F.jpg

Upvotes: 2

Views: 4097

Answers (2)

Tejas
Tejas

Reputation: 304

If you run docker ps you will see something like this 0.0.0.0:49005->8080/tcp in your ports section for your container.

If you are using docker run then you need to do docker run -p 49005:49005 my-image

or

If you are using docker-compose then you need to add

    ports:
      - "49005:49005"

Upvotes: 0

user54
user54

Reputation: 583

Probably those ports are not mapped into host machine where the container is being run. There is a directive in docker-compose file ports. In order to map ports into host machine just specify associated ports via which destination one inside container will be accessible from host machine. E.g:

ports: 
   - 7777:7777 

Thus, 7777 inside container will be accessible via 7777 which is on host. Left side host one and right side container one. See docs for more details: https://docs.docker.com/compose/compose-file/#ports
Apologize if I understood your question incorrectly.

Upvotes: 1

Related Questions