2

I'm new to Docker Compose, but have used Docker for years. The screen shot below is of PowerShell and of GitBash. If I run containers without docker-compose I can docker exec -it <container_ref> /bin/bash with no problems from either of these shells. However, when running using docker-compose up both shells give no error when attempting to use docker-compose exec. They both just hang a few seconds and return to prompt. Lastly, for some reason I do get an error in GitBash when using what I know: docker exec.... I've used this for years so I'm perplexed and posting a question. What does Docker Compose do that messes with GitBash docker ability, but not with PowerShell? And, why the hang when using docker-compose exec..., but no error? can exec using powershell but not gitbash

I am using tty: true in the docker-compose.yml, but that honestly doesn't seem to make a difference. Not to throw a bunch of questions in one post, but whatever is going on could it also be the reason I can't hit my web server in the browser only when using Docker Compose to run it?

version: '3.8'

volumes:
  pgdata:
     external: true   

services:
    db:
        image: postgres
        container_name: trac-db
        tty: true
        restart: 'unless-stopped'
        environment:
            POSTGRES_PASSWORD: postgres
            POSTGRES_USER: postgres
            POSTGRES_DB: iol
        volumes:
            - pgdata:/var/lib/postgresql/data
        network_mode: 'host'
        expose:
            - 5432
    web:
        image: lindben/trac-server
        container_name: trac-server
        tty: true
        restart: 'unless-stopped'
        environment:
            ADDRESS: localhost
            PORT: 3000
            NODE_ENV: development
        depends_on:
            - db
        network_mode: 'host'
        privileged: true
        expose:
            - 1234
            - 3000
    ```
Neil Gaetano Lindberg
  • 2,488
  • 26
  • 23

1 Answers1

2

Issue explanation

I'm going to be assuming you're using Docker for Desktop and so the reason you can docker exec just fine using PowerShell is because both PS and Docker for Desktop built for windows while GitBash which is based on bash which isn't natively used in Windows but in Linux and is based on the Linux shell (bash = Bourne-Again SHell).

Basic Solution

So when using a windows program that needs a tty you need some sort of "adapter", like winpty for example, to bridge the gap between Docker for Desktop native interface and GitBash's (or Bash's) one.

Here's a more detailed explanation on winpty

Better Solution - specific

putting all of this aside, if trying only to use the compose options it maybe better for you to advise this question

Subsequent Hangup Issue

Now, regarding your web service issue, I think that you're not actually publicly exposing your application using the expose tag. take a look at the docker-compose expose reference. what you need is to add a "ports" tag like so as referenced here:

db:
    ports:
      - "5432:5432"
web:
    ports:
      - "1234:1234"
      - "3000:3000"

I hope this solves your pickle ;)

Noam Yizraeli
  • 4,446
  • 18
  • 35
  • Thank you for the info. I cannot use ports and use `network: host`. I need to use `network: host` to send email because just mapping port 25:25 doesn't work on my remote dev machine as IT only has the host white listed. BTW, is there maybe a way to tell Docker for Desktop to use GitBash instead? It seems fairly inflexible in that way. I actually do `docker-compose up` in a VSCode GitBash Integrated Terminal. – Neil Gaetano Lindberg Aug 24 '21 at 20:50
  • I guess you technically did answer my question, but if anybody else has a way to tell Docker Desktop to use GitBash that'd be wonderful! – Neil Gaetano Lindberg Aug 24 '21 at 21:06