Monthly Archives: March 2019

How to use ipdb with docker-compose

Sometimes there may be in issue you need to debug which only occurs within a Docker container. However by default ipdb.set_trace() won’t work. Here’s how to get it working.

Enable interactive mode by adding stdin_open and tty the following to your docker-compose.yml. For example:

version: "3"
services:
  app_tests:
    build: .
    stdin_open: true
    tty: true
    command: ./run_my_tests.sh

Now when you run your tests (docker-compose run app_tests) the terminal will stop at your break point.

Attach your local to the container. In another terminal window run docker attach <container_id> which will bring up the ipdb interactive session in your terminal.

How to use localstack with Gitlab CI

If you’re using a standard style .gitlab-ci.yml format such as the below, it won’t work.

image: ubuntu

services:
  - localstack/localstack:latest

variables:
  SERVICES: s3
  DEFAULT_REGION: eu-west-1
  AWS_ACCESS_KEY_ID: localkey
  AWS_SECRET_ACCESS_KEY: localsecret
  HOSTNAME_EXTERNAL: localstack
  HOSTNAME: localstack
  S3_PORT_EXTERNAL: 4572
  LOCALSTACK_HOSTNAME: localstack

test:python36:
  script:
    - pip install awscli
    - aws s3api list-buckets --endpoint-url=http://localstack:4572
Could not connect to the endpoint URL: "http://localstack:4572/"
ERROR: Job failed: exit code 1

However if you use build stages instead as below, it will work.

stages:
  - test

test-application:
  stage: test
  image: ubuntu
  variables:
    SERVICES: s3:4572
    HOSTNAME_EXTERNAL: localstack 
    DEFAULT_REGION: eu-west-1
    AWS_ACCESS_KEY_ID: localkey
    AWS_SECRET_ACCESS_KEY: localsecret
  services:
    - name: localstack/localstack
      alias: localstack
  script:
    - pip install awscli
    - aws s3api list-buckets --endpoint-url=http://localstack:4572
{
    "Buckets": [],
    "Owner": {
        "DisplayName": "webfile",
        "ID": "bcaf1ffd86f41161ca5fb16fd081034f"
    }
}
Job succeeded