devel0pp3r
devel0pp3r

Reputation: 105

Docker CodeIgniter Routes Redirects to Docker IP

I am trying to run a CodeIgniter project inside a Docker Container. My base image is Ubuntu 16.04 in which I have installed a LAMP stack. My container has a Volume mounted from my host machine where my Project Resides. My docker run command is as follows.

docker run -ti -v /Users/user/Documents/projects:/var/www/html  -p 80:80 -p 3306:3306 ubuntu

The problem is whenever I try to run the project as http://localhost/project/, it is getting redirected to Docker's local Ethernet IP such as 172.17.0.2/project/

But if I test it with a simple phpinfo file, it runs fine.

My Machine : macOS Sierra

Docker Image : Ubuntu 16.04

Upvotes: 0

Views: 763

Answers (2)

elKuba
elKuba

Reputation: 101

Try to set $config['base_url'] = 'http://127.0.0.1/' (or whatever fits you) in config.php, because if the value is not set it will be as follow (it is written in config file description, right above base_url):

If it is not set, then CodeIgniter will try guess the protocol and path your installation, but due to security concerns the hostname will be set to $_SERVER['SERVER_ADDR'] if available, or localhost otherwise.

So I guess you didn't set this value and CodeIgniter used 172.17.0.2 because it is $_SERVER['SERVER_ADDR'].

Upvotes: 0

Ratul
Ratul

Reputation: 451

Check your apache proxy configuration. Can you change the host_port and again check? I'm using nginx -p 127.0.0.1:80:80. Check your local ip/ports using **sudo netstat -plunt** and also check this sudo iptables -t nat -L -n

Upvotes: 2

Related Questions