加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

Docker Compose不绑定端口

发布时间:2020-12-16 03:53:24 所属栏目:安全 来源:网络整理
导读:我的容器有以下Dockerfile: FROM centos:centos7# Install softwareRUN yum -y update yum clean allRUN yum install -y tar gzip wget yum clean all# Install io.jsRUN mkdir /root/iojsRUN wget https://iojs.org/dist/v1.1.0/iojs-v1.1.0-linux-x64.tar

我的容器有以下Dockerfile:

FROM        centos:centos7

# Install software
RUN         yum -y update && yum clean all
RUN         yum install -y tar gzip wget && yum clean all

# Install io.js
RUN         mkdir /root/iojs
RUN         wget https://iojs.org/dist/v1.1.0/iojs-v1.1.0-linux-x64.tar.gz
RUN         tar -zxvf iojs-v1.1.0-linux-x64.tar.gz -C /root/iojs
RUN         rm -f iojs-v1.1.0-linux-x64.tar.gz

# add io.js to path
RUN         echo "PATH=$PATH:/root/iojs/iojs-v1.1.0-linux-x64/bin" >> /root/.bashrc

# go to /src
WORKDIR     /src

CMD         /bin/bash

我构建这个容器并使用docker run -i -t -p 8080:8080 -v / srv / source:/usr/src / app -w /usr/src / app –rm iojs-dev bash启动映像. Docker将端口8080绑定到主机端口8080,以便我可以从我的客户端访问iojs-application.一切正常.

现在我想用docker-compose启动我的容器,使用以下docker-compose.yml

webfrontend:
    image: iojs-dev
    links:
        - db
    command: bash -c "iojs test.js"
    ports:
        - "127.0.0.1:8080:8080"
    volumes:
        - /srv/source:/usr/src/app
        - /logs:/logs
db:
    image: mariadb
    environment:
        MYSQL_ROOT_PASSWORD: 12345

当我现在运行docker-compose运行webfrontend bash时,我无法访问主机上的端口8080.没有端口绑定. docker ports的结果为空,并且docker inspect的结果在端口设置为空:

"NetworkSettings": {
    "Bridge": "docker0","Gateway": "172.17.42.1","IPAddress": "172.17.0.51","IPPrefixLen": 16,"MacAddress": "02:42:ac:11:00:33","PortMapping": null,"Ports": {
        "8080/tcp": null
    }
},"HostConfig": {
    "Binds": [
        "/srv/source:/usr/src/app:rw","/logs:/logs:rw"
    ],"CapAdd": null,"CapDrop": null,"ContainerIDFile": "","Devices": null,"Dns": null,"DnsSearch": null,"ExtraHosts": null,"Links": [
        "/docker_db_1:/docker_webfrontend_run_34/db","/docker_db_1:/docker_webfrontend_run_34/db_1","/docker_db_1:/docker_webfrontend_run_34/docker_db_1"
    ],"LxcConf": null,"NetworkMode": "bridge","PortBindings": null,"Privileged": false,"PublishAllPorts": false,"RestartPolicy": {
        "MaximumRetryCount": 0,"Name": ""
    },"SecurityOpt": null,"VolumesFrom": []
},
最佳答案
这是无花果运行的故意行为.

Run a one-off command on a service.

One-off commands are started in new containers with the same config as a normal container for that service,so volumes,links,etc will all be created as expected. The only thing different to a normal container is the command will be overridden with the one specified and no ports will be created in case they collide.

source.

fig up可能是你正在寻找的命令,它会(重新)根据你的fig.yml创建所有容器并启动它们.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读