I have the following Docker file for my container:
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
I create this container and run the image using docker run -i -t -p 8080:8080 -v /srv/source:/usr/src/app -w /usr/src/app --rm iojs-dev bash . Docker associates port 8080 with host port 8080 so that I can access the iojs application from my client. Everything is working fine.
Now I want to start my container using docker-compose using the following docker-compose.yml file
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
When I run docker-compose run webfrontend bash , I cannot access port 8080 on my host. The port was not tied. The result of docker ports empty, and the result of docker inspect empty in the port settings:
"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": [] },
docker docker-compose fig
rotespferd
source share