Unable to connect to Docker container from browser on host

Asked 2 years ago, Updated 2 years ago, 132 views

How do I connect to a Docker container port from a browser on my host?
The Dockerfile, docker-compose.yml below allows the host to connect to port 1344, but even if you access localhost:1344 in the host browser, you will not be able to establish a connection to the server

On port 1344, I run the bottle (waf of python) application

Docker version:Docker 1.12.0-rc4-beta19
OS:OS X 10.11.6

Dockerfile:

 from ubuntu:latest
maintainer myname

run mkdir~/app

copy vim /root /.vim
copy vimrc /root /.vimrc
# update
run apt-get update

run apt-get-y update
run apt-get-y install libssl-dev
run apt-get-yf install curl 
run apt-get-y install clang 
run apt-get-y install lldb 
run apt-get-y install make 
run apt-get-y install libsqlite3-dev
run apt-get-y install man 
run apt-get-y install vim 
run apt-get-y install git 
run apt-get-y install pkg-config 
run apt-get-y install zip 
run apt-get-y install unzip
run apt-get-y install language-pack-ja-base
run apt-get-y install language-pack-ja
run apt-get-y install language-pack-en-base
run apt-get-y install language-pack-en
run apt-get-y install fcitx-mozc
run apt-get-y install libreadline-dev

# setting locale to Japanese

run update-locale LANG=ja_JP.UTF-8LANGUAGE=ja_JP:ja
envLANGja_JP.UTF-8
envLC_CTYPE ja_JP.UTF-8
envLC_MESSAGES en_US.UTF-8
runim-config-n fcitx

# end of locale settings

# install postgresql

    run apt-get install postgresql
    run apt-get install libpq-dev
    run apt-get install postgresql-plpython 3-9.5

# install latest python 3 and some python packages (https://github.com/docker-library/python/blob/3db904b3f5407840e591daf3aa54670a685b22b3/3.5/Dockerfile)

    ENV GPG_KEY97FC712E4C024BBEA48A61ED3A5CA953F73C700D

    ENV PYTHON_VERSION 3.5.2

    # if this is called "PIP_VERSION", pip explodes with "ValueError: invalid true value'<VERSION>"
    ENV PYTHON_PIP_VERSION 8.1.2

    RUN set-ex\
        &curl-fSL"https://www.python.org/ftp/python/$ {PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz"-opython.tar.xz\
        &curl-fSL"https://www.python.org/ftp/python/$ {PYTHON_VERSION%%[a-z]*}/Python-$PYTHON_VERSION.tar.xz.asc"-opython.tar.xz.asc\
        &export GNUPGHOME="$(mktemp-d)"\
        &gpg --keyserver ha.pool.sks-keyservers.net --recv-keys "$GPG_KEY"\
        &gpg --batch -- verify python.tar.xz.asc python.tar.xz\
        &rm-r "$GNUPGHOME" python.tar.xz.asc\
        &mkdir-p/usr/src/python\
        &tar-xJC/usr/src/python -- strip-components=1-f python.tar.xz\
        &rmpython.tar.xz\
        \
        &cd/usr/src/python\
        &./configure\
            --enable-loadable-sqlite-extensions\
            --enable-shared\
        &make-j$(nproc)\
        & make install\
        &ldconfig\
        &pip3 install --no-cache-dir --upgrade pip==$PYTHON_PIP_VERSION\
        &[$(pip list | awk-F'[()]+'$1=="pip"{print$2; exit}')"="$PYTHON_PIP_VERSION"]\
        &find/usr/local-depth\
            \( \
                \(-type d-a-name tests-o-name tests\)\
                -o\
                \(-type f-a-name'*.pyc'-o-name'*.pyo'\)\
            \)-execrm-rf'{}'+\
        &rm-rf/usr/src/python~/.cache

    # make some useful symlinks that are expected to exist
    RUN cd/usr/local/bin\
        &ln-seasy_install-3.5easy_install\
        &ln-side 3 idle\
        &ln-spydoc3pydoc\
        &ln-spython 3 python\
    &ln-spython3-config python-config

    # install some packages

    run pip -- no-cache-dir install bottle
    run pip -- no-cache-dir install feedparser
    run pip -- no-cache-dir install psycopg2
    run pip --no-cache-dir install-Upip
    run pip --no-cache-dir install-U setup tools

# end of latest python installation

# prompt and compiler environment variables
env CC clang
env CXX clang++
run echo'export PS1="\h:\W\u$"'>>~/.bashrc

# git config
run git config --global user.name "myname"
rungit config --global user.email "[email protected] address"
runit config --global color.ui true
runit config --global core.editor vim

expose1000
expose 2000
expose3000
expose4000
expose 5000

expose1344

docker-compose.yml:

version: '2'
services:
    datastore:
        image:busybox:latest
        volumes:
            - ./share: /share_to_container

    ### base(ubuntu)
    base:
        build:./
        ports:
            - "1344:1344"
            - "8000:8000"
        volumes:
            - ./app: /app
        volumes_from:
            - datastore
        links:
            - db
            - webserver


    db:
        build: 
            context:.
            dockerfile: "mysqlfile"
        environment:
            - MYSQL_ROOT_PASSWORD=hello
        ports:
            - "3306:3306"
        volumes:
            - ./mysql:/mysql
        volumes_from:
            - datastore

    webserver:
        image —nginx
        ports:
            - "8080:80"
        volumes:
            - ./nginx/mysite.template: /etc/nginx/conf.d/mysite.template
        volumes_from:
            - datastore

docker docker-compose

2022-09-30 21:16

1 Answers

This is probably because there is no description of CMD (or ENTRYPOINT) in the Dockerfile.

I'm not familiar with Python, so I can't give you a specific example, but I think I should write a command to run the bottle.

Also, if you try docker run and check the process with the ps command, it may not work.


2022-09-30 21:16

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.