简体   繁体   English

暴露Docker容器端口不起作用

[英]Exposing docker container ports not working

I am having trouble exposing a port from a docker container to my server. 我在将端口从Docker容器暴露到服务器时遇到麻烦。 Here is what I've done: 这是我所做的:

I wrote a very simple spring boot app that runs on port 8080. 我编写了一个非常简单的spring boot应用程序,该应用程序在端口8080上运行。
Now I am trying to deploy it into a docker container on my server. 现在,我正在尝试将其部署到服务器上的docker容器中。 Based on the Spring - Getting started with Docker Userguide I've created the following Dockerfile: 基于春季 -Docker用户指南入门,我创建了以下Dockerfile:

FROM openjdk:8-jdk-alpine
VOLUME /tmp
ARG JAR_FILE
COPY ${JAR_FILE} app.jar
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]

In a second step I copied my jar to the same directory (where the dockerfile is stored) and built the container with the following command: 在第二步中,我将jar复制到了相同的目录(存储dockerfile的目录),并使用以下命令构建了容器:

docker build . -t testportmapping --build-arg JAR_FILE=swagger-v2-person-ws-0.0.1-SNAPSHOT.jar

Now when I run: 现在,当我运行时:

docker run -d testportmapping:latest -p 9065:8080

The command runs without an error. 该命令运行无错误。 But if I take a look at: docker container ls : I see that no portmapping was created: 但是,如果我看一下: docker container ls :我发现没有创建端口映射:

CONTAINER ID        IMAGE                    COMMAND                  CREATED               STATUS              PORTS                 NAMES
f15639c81903        testportmapping:latest   "java -Djava.securit…"   About 6 minutes ago   Up 6 minutes                              mystifying_payne

Does anyone know that I am doing wrong? 有人知道我做错了吗?

What I've tried so far: 到目前为止,我已经尝试过:

  1. Using different local port 使用其他本地端口
  2. Adding an EXPOSE to the Dockerfile 向Dockerfile添加EXPOSE
  3. Addinng --net=host to the docker run command --net=host--net=host docker run命令
  4. Running the container attached to see if the app starts up correctly (it does) 运行附加的容器以查看应用程序是否正确启动(确实)

My setup: 我的设置:

root@jupiter /h/n/d/p/swagger-v2# docker version
Client:
 Version:           18.06.1-ce
 API version:       1.38
 Go version:        go1.10.3
 Git commit:        e68fc7a
 Built:             Tue Aug 21 17:24:56 2018
 OS/Arch:           linux/amd64
 Experimental:      false

Server:
  Engine:
  Version:          18.06.1-ce
  API version:      1.38 (minimum version 1.12)
  Go version:       go1.10.3
  Git commit:       e68fc7a
  Built:            Tue Aug 21 17:23:21 2018
  OS/Arch:          linux/amd64
  Experimental:     false


root@jupiter /h/n/d/p/swagger-v2# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.5 LTS
Release:        16.04
Codename:       xenial

Run below command 在命令下面运行

docker run -d -p 9065:8080 testportmapping:latest

Image name should be the last parameters and all other parameters should come before it. 映像名称应为最后一个参数,所有其他参数应位于其后。

PS As mentioned by @David Maze in the comments, whatever comes after the image name is passed on to the container PS正如@David Maze在评论中提到的,将映像名称传递到容器之后的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM