Localhost doesn't forward requests to Oracle Docker container

2k views Asked by At

I'm trying to switch from Vagrant to Docker (too late to go back now).

I've deleted my Oracle Vbox already, and I have:

So I created the Docker container using this command :

docker run -d -p 8080:8080 -p 1521:1521 sath89/oracle-12c

Then I tried to setup users/permission etc using localhost:8080/em which was unreachable.

Then I opened Kinematic to see if I could find my container IP and I found there that my Docker container IP is 192.x.x.x

I was able to login into 192.x.x.x:8080/em and setup what I needed to setup.

And my app is connecting to the Docker when I specify the docker ip: 192.x.x.x

But it should be really connecting via localhost, why is the localhost:8080/em not working and why is the app not able to connect to Docker container via localhost?

It's working for all my other team-mates, I'm using mac OS Sierra.

2

There are 2 answers

0
Alexandre FILLATRE On BEST ANSWER

Short answer:

Despite what I said in my comment, it turns out you didn't wait long enough before trying to connect to the container. Display the logs to see when init is done, then try again.

Long answer:

I got it working this way. First, I started the container (I only added the --name for simplicity sake):

$> docker run -d -p 8080:8080 -p 1521:1521 --name oracle-12c sath89/oracle-12c

Then I tried to connect to the container, doing a simple:

$> curl http://localhot:8080
curl: (52) Empty reply from server

That didn't work, so I displayed the container's logs:

$> docker logs -f oracle-12c

It showed me that the container needed time to start up, with the following logs:

ls: cannot access /u01/app/oracle/oradata: No such file or directory
Database not initialized. Initializing database.
Starting tnslsnr
Copying database files
1% complete
3% complete
11% complete
18% complete
37% complete
Creating and starting Oracle instance
40% complete
45% complete
50% complete
55% complete
56% complete
60% complete
62% complete
Completing Database Creation
66% complete
70% complete
73% complete
85% complete
96% complete
100% complete
Look at the log file "/u01/app/oracle/cfgtoollogs/dbca/xe/xe.log" for further details.
Configuring Apex console
Database initialized. Please visit http://#containeer:8080/em http://#containeer:8080/apex for extra configuration if needed
Starting web management console

PL/SQL procedure successfully completed.

Starting import from '/docker-entrypoint-initdb.d':
found file /docker-entrypoint-initdb.d//docker-entrypoint-initdb.d/*
[IMPORT] /entrypoint.sh: ignoring /docker-entrypoint-initdb.d/*

Import finished

Database ready to use. Enjoy! ;)

It took me about 15min to init the db. Then it was working

0
Alexandre FILLATRE On

So it turns out you're using Docker Machine rather than Docker for Mac. Here are your options:

Keep Docker machine:

Docker machine is great if you want multiple docker envs (for instance, one per project), but it has the downside to force you to use the daemon ip to connect containers rather than just localhost.

Though, you could edit your /etc/hosts file to add an alias to your docker daemon ip, for easier use.

The daemon IP can be found with docker-machine env <your_env>.

Switch to Docker for Mac:

How to do that is described here: https://docs.docker.com/docker-for-mac/

Basically, both Docker machine (Docker Toolbox) and Docker for Mac can coexist. Whether you actually want to keep Docker machine is up to you. Docker for Mac will use Docker machine default env as its only env, accessible by localhost.

In this case, start your oracle container on the default env (i.e. open a new bash session once Docker for Mac is running), and when all it initialised, you"ll be able to access it directly from your localhost.