Docker Compose不绑定端口

前端之家收集整理的这篇文章主要介绍了Docker Compose不绑定端口前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我的容器有以下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创建所有容器并启动它们.

原文链接:https://www.f2er.com/docker/436724.html

猜你在找的Docker相关文章