Skip to content

docker compose

ed-mare edited this page Feb 23, 2020 · 9 revisions

Commands

# rebuild and reload one container in a single step (compose 1.18.x) 
docker-compose up --force-recreate --build <one service>

# or... 
docker-compose build <one service>
# stop all containers 
# start all containers

Logs

You can specify the log driver and options in docker-compose. json-file driver (docker default) offers rolling log options. Logging drivers have different options.

services:
  some-service:
    image: some-service
    logging:
      driver: "json-file"
      options:
        max-size: "200k"
        max-file: "10"

AWS has its own driver which logs to Amazon Cloud Watch. Log entries can be retrieved through the AWS Management Console or the AWS SDKs and Command Line Tools. To use the awslogs driver as the default logging driver, set the log-driver and log-opt keys to appropriate values in the daemon.json file, which is located in /etc/docker/

{
  "log-driver": "awslogs",
  "log-opts": {
    "awslogs-region": "us-east-1"
  }
}

Hosts

Add hostname mappings inside containers.

services:
  foo:
    image: "foo/bar"
    tty: true
    ports:
      - 4444:4444
    extra_hosts:
      - "admin.foo.local:127.0.0.1"

This adds the following to /etc/hosts inside the foo container:

127.0.0.1	admin.foo.local

Aliases (alternative hostnames) for this service on the network. Other containers on the same network can use either the service name or this alias to connect to one of the service’s containers.

test_db:
    image: postgres:9.6.3
    ports:
      - 5751:5432
    networks:
      default:
        aliases:
          - someothername 

Troubleshooting

Getting error...

docker-compose build <project> Building <project> ERROR: Couldn't connect to Docker daemon at http+docker://localunixsocket - is it running? If it's at a non-standard location, specify the URL with the DOCKER_HOST environment variable.

Try:

sudo chmod 755 <possible offending files>

If that doesn't work, see other answers at StackOverflow.

Clone this wiki locally