我已经使用docker-ce设置了一个Ubuntu服务器。在这里,我正在运行一个小型的码头集装箱,工作正常。它启动一个tomcat映像,将8080暴露给本地端口80.我已经测试了docker exec -it
,它可以工作。
但是当我抛出浏览器并尝试通过我的ubuntu主机IP地址访问它时,我什么都没得到。如果我打开终端并通过SSH连接到我的ubuntu服务器并尝试curl localhost
,我会收到连接拒绝错误。
我检查了我的iptables,并且DOCKER存在一个链,其中包含0.0.0.0/0的源和暴露的tcp dpt:80端口。
在谷歌上搜索,我看到有人引用docker-machine
。这没有安装,所以我安装了它。这需要我创建一些东西,所以我尝试创建一个docker-machine。但这需要virtualbox,所以我安装了它。在我修改我的BIOS之前,Virtualbox才会启动.... 这是不是必须这样做?
我认为只安装docker-ce就足够了。在我的本地Windows机器上就足够了,为什么在我的云托管的ubuntu服务器上它不够呢?我错过了什么?
Dockerfile
#####################
## Stage 1: Build ##
# We base this builder on tomcat, as our build script relies heavily
# on tomcat libraries
FROM tomcat:7.0-jre7 as builder
# Install sources
RUN curl -sL https://deb.nodesource.com/setup_9.x | bash && \
curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
# We install our build environment (java 1.7, ant and node)
RUN apt-get update && apt-get install -y openjdk-7-jdk ant apt-transport-https nodejs yarn git
# We set the java options needed to compile this
ENV JAVA_OPTS="-Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false -XX:MaxPermSize=512m"
# Then we copy in our app and libraries used for building it
WORKDIR /usr/src/app
COPY . .
COPY tomcat/lib /usr/local/tomcat/lib
# Run frontend dependency installation (npm and bower)
RUN echo '{ "allow_root": true }' > /root/.bowerrc && yarn install
# We build it (this will also deploy it to this tomcat container
# but the tomcat container will never startup before the build stage
# is discarded)
RUN ant clean init jar-dev-configuration compile deploy
#####################
## Stage 2: Runner ##
FROM tomcat:7.0-jre7-alpine
# Copy in local configuration
COPY tomcat/conf /usr/local/tomcat/conf
COPY tomcat/lib /usr/local/tomcat/lib
# Copy in built products
COPY --from=builder /usr/local/tomcat/webapps/kx /usr/local/tomcat/webapps/kx
COPY --from=builder /usr/local/tomcat/webapps/portal /usr/local/tomcat/webapps/portal
EXPOSE 8080
搬运工-compose.yml
version: '3'
services:
web:
build: .
ports:
- 8080:80
volumes:
# Upload folders should be local
- ./upload:/usr/local/tomcat/webapps/portal/upload:rw
答案 0 :(得分:2)
根据给定的信息,我可以告诉您,在docker-compose.yml
中,您将端口8080
暴露给您的主机(因此,向世界)和端口80
到您的容器中。
尝试将它们换成:
ports:
# host:container
- 80:8080