1

Intention: I am trying to figure out how to use the command docker-compose up --build to build a machine with an Apache/PHP7.1 service acting as a web server and a MSSQL service as the database for the app that is served from the web server.

I need to be able to type in commands to the docker container while I build this development environment (so that I can look at the PHP logs, etc), but since the web server is running, my terminal is occupied with the output from the web server and when I press ctrl+Z, it actually puts the docker process in the background.

The question: Is there anyway that I can run this docker-compose.yml file and have it drop me into the shell on the guest machine?

Service 1:

webserver:
    image: php:7.1-apache
    stdin_open: true
    tty: true
    volumes:
      - ./www:/var/www/html
    ports:
      - 5001:80

Service 2:

mssql:
    image: microsoft/mssql-server-linux
    stdin_open: true
    tty: true
    environment:
      - ACCEPT_EULA=Y
    volumes:
      - ./www:/var/www/html
    ports:
      - 1433:1433
    depends_on:
      -webserver
Moose
  • 1,270
  • 2
  • 19
  • 33
  • 1
    The plain `docker` answer applies as well here as well: https://stackoverflow.com/q/17903705/1318694 – Matt Oct 07 '17 at 01:32

2 Answers2

6

You can exec a new process in a running container.

docker-compose exec [options] SERVICE COMMAND [ARGS...]

In your case

docker-compose exec webserver bash

The -i and -t options from docker exec are assumed in docker-compose exec

Matt
  • 68,711
  • 7
  • 155
  • 158
2

First of all, same as docker run, docker-compose has an option for running the services/containers in the background.

docker-compose up --detach --build

After that, list the running containers with:

docker-compose ps

And connect to the container like @Matt already answered.

Luminance
  • 820
  • 1
  • 10
  • 24