tomaytotomato
tomaytotomato

Reputation: 4028

Accessing microservice inside Docker container?

I have a Dropwizard Microservice running in a container on port 9000.

In the Dockerfile I exposed the port like so

FROM maven:3.3-jdk-8-alpine

# Install packages
RUN apk add --no-cache curl tar bash wget

EXPOSE 9000

Then I ran the container like so

docker run --add-host="localhost:10.0.2.2" -t foo-service

However when I try to access it at localhost:9000 I do not get a reponse in the browser.

How can I access the Microservice from the Docker host?

Docker host is Ubuntu 16.04

Many thanks

Upvotes: 0

Views: 382

Answers (1)

mickadoo
mickadoo

Reputation: 3483

EXPOSE doesn't actually allow you to access that port from outside docker. It's a way of allowing other containers to access that port

If you want to be able to access port 9000 from your browser you'll need to add -p 9000:9000 to your run command. This is a port mapping which maps your host machines port to the port on the container.

Upvotes: 1

Related Questions