Docker - 无法通过容器中的端口

时间:2018-03-24 22:16:45

标签: python docker docker-compose

我无法通过容器中的端口。我使用了这个地址:0.0.0.0.:5000并查看:http://joxi.ru/Vm6oegWtxoQVK2。我正在经历:' docker-compose up -d'。输入此命令后,#docker ps'我明白了:

const sequelize = require('sequelize');
const DataTypes = require('mysql');
/**
 * User model
 */
const User = sequelize.define('user', {

  id: {
    type: DataTypes.INTEGER,
  },
  name: {
    type: DataTypes.STRING,
  },
  email: {
    type: DataTypes.STRING,
  },
  lastEmail: {
    type: DataTypes.TIME,
  }
});

多克尔-撰写:

CONTAINER ID        IMAGE               COMMAND                  CREATED             STATUS              PORTS                    NAMES
4fea50856eef        docker_web          "python manage.py ru…"   13 seconds ago      Up 11 seconds       0.0.0.0:5000->5000/tcp   docker_web_1

Docerfile

version: '3'

services:
  web:
    build:
      context: .
      dockerfile: /django.testsite/Dockerfile
    ports:
      - "5000:5000"

如何解决?

1 个答案:

答案 0 :(得分:0)

问题是你没有公开Dockerfile中的端口。添加

在CMD之前的Dockerfile中

EXPOSE 8000

例如:

FROM python:3

RUN easy_install pip
RUN pip install django==1.9.12
RUN pip install requests

ADD . /.
WORKDIR /django.testsite
EXPOSE 8000
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]

了解更多信息https://docs.docker.com/engine/reference/builder/#expose