Docker - cannot access container from Mac Host

I cannot access a simple Docker container running locally on my mac. I can start curl localhostfrom the container and see that the Apache page is set by default, but I cannot hit it from the browser.

I am wondering if I have a problem with VirtualBox configuration or something like that. Any help in diagnosing the problem?

Dockerfile

# Build the image of ubuntu 12.04 LTS
from ubuntu:precise

# Run apt-get update
run apt-get -y update

# Install LAMP
run DEBIAN_FRONTEND=noninteractive apt-get -y install lamp-server^
run apt-get -y install vim-tiny curl wget

# Put custom scripts in the container and give proper permissions to them
add ./startup.sh /usr/local/bin/startup.sh
run chmod 755 /usr/local/bin/startup.sh

add site.vhost /etc/apache2/sites-available/site
run a2ensite site

# Expose port 80 to the host machine
expose 80

site.vhost

<VirtualHost *:80>

    ServerAdmin webmaster@localhost

    DocumentRoot /var/www
    <Directory /var/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        #Order allow,deny allow from all
    </Directory>

    # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg.
    LogLevel warn
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

startup.sh

#!/bin/bash

a2dissite default
apache2ctl graceful
/usr/bin/mysqld_safe &

To start ...

I will create an image with docker build -t test1 .- which seems to work fine.

On initial setup, I run docker run -d -v $(pwd)/mysql:/tmp/mysql test1 /bin/bash -c "cp -rp /var/lib/mysql/* /tmp/mysql"to install MySQL.

Then I ran docker run -i -t -v $(pwd)/mysql:/var/lib/mysql -v $(pwd)/www:/var/www -p 8080:80 test1 /bin/bashto run the actual instance.

service apache2 start, , , . curl localhost, .

, , . http://127.0.0.1:8080 80, ?

+4
4

. "" : ( http://docs.docker.io/en/latest/installation/mac/#forwarding-vm-port-range-to-host)

# vm must be powered off
for i in {49000..49900}; do
 VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port$i,tcp,,$i,,$i";
 VBoxManage modifyvm "boot2docker-vm" --natpf1 "udp-port$i,udp,,$i,,$i";
done

8080:

VBoxManage modifyvm "boot2docker-vm" --natpf1 "tcp-port8080,tcp,,8080,,8080"

... , , 8080 Mac.

+9

, , Docker 1.8 , Andy Muneeb ( ), boot2docker - VM [1].

Mac → VM →

80 , 8080 Mac, :

a) 80 EXPOSE 80 Docker, --expose=80 docker run. /udp UDP.

b) VM -p 8080:80 docker run. /udp UDP.

c) ( " " ), NAT 8080 8080 Mac:   VBoxManage controlvm default natpf1 'port8080,tcp,,8080,,8080'. Mac; . , VBoxManage controlvm default natpf1 delete port8080. : VBoxManage controlvm , modifyvm .

IP- - VM

docker-machine ip default ( VM).

[1] https://docs.docker.com/installation/mac/

+7

localhost (127.0.0.1), Mac OS X. . :

boot2docker ip

IP- , , ip_address: , , 192.168.59.103:8080 ( 192.168.59.103 IP-, )

+4

Source: https://habr.com/ru/post/1535619/


All Articles