Kenny Ostrom
Kenny Ostrom

Reputation: 5871

docker compose not exposing ports

I have a dockerfile that works by itself, with

docker build -t image_apache .
docker run -tid -p 5000:80 --name=container_apache image_apache

This works, and I can connect to its webserver with 127.0.0.1:5000

But when I try to create a docker-compose.yml file to build and run the image with docker-compose, it doesn't appear to expose the port at all.

Here is the docker-compose.yaml

version: '3'

services:
  deploy_test:
    ports:
      - "8080:80"
    build: .
    working_dir: /tmp/artifacts

docker-compose build
docker-compose run deploy_test

My browser can't connect to 127.0.0.1:8080, and the apache log in the container doesn't show any attempts.

Do I just have a bad syntax for the port? It matches online samples.

Upvotes: 4

Views: 12235

Answers (1)

semicolon
semicolon

Reputation: 545

please try using docker-compose run -p 8080:80 deploy_test as run command can not expose/publish ports by itself i.e. you need to specify it manually. For more information regarding same, please refer to its official documentation here.

Upvotes: 12

Related Questions