How fix mounting issue while using docker-compose.

2019-08-20 03:31发布

I am using test containers to run some tests and using https://www.testcontainers.org/modules/docker_compose/ to spin some containers used for my tests. Similar to generic containers support, it's also possible to run a bespoke set of services specified in a docker-compose.yml file.

This is intended to be useful on projects where Docker Compose is already used in dev or other environments to define services that an application may be dependent upon.

Here is my code to include docker-compose.yml

@ClassRule
public static DockerComposeContainer environment =
    new DockerComposeContainer(new File("src/test/resources/docker-compose.yml"));

Here is the content of my yml file:

version: '2.0'
services:

  vault:
    image: vault:0.10.2
    container_name: vault
    ports:
      - "8200:8200"
    environment:
      - VAULT_ADDR=http://0.0.0.0:8200
      - VAULT_DEV_LISTEN_ADDRESS=0.0.0.0:8200
      - VAULT_DEV_ROOT_TOKEN_ID=stupid-token
    volumes:
      - /config/vault/start.sh:/start.sh
    command: sh -c "./start.sh"

  consul:
    image: consul:0.8.5
    container_name: consul
    ports:
      - "8300:8300"
      - "8400:8400"
      - "8500:8500"
      - "8600:8600"
      - "8600:8600/udp"
    environment:
      - SERVICE_IGNORE=true
    entrypoint: sh -c "BIND_HOST=$$(echo \"$DOCKER_HOST\" | awk -F ':' '{print $$2}' | sed  's/\\/\\///'); echo $$BIND_HOST;/bin/consul agent -server -bootstrap  --client=0.0.0.0 --data-dir=/tmp/consul -ui -advertise=$$BIND_HOST -domain=consul-dev"

  registrator:
    image: gliderlabs/registrator:v7
    container_name: registrator
    depends_on:
      - consul
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
    entrypoint: sh -c "BIND_HOST=$$(echo \"$DOCKER_HOST\" | awk -F ':' '{print $$2}' | sed  's/\\/\\///'); echo $$BIND_HOST;/bin/registrator -ip $$BIND_HOST consul://consul:8500"

  postgres:
    image: registry.xxx.com/xxx-postgres:9.5.9
    container_name: postgres
    ports:
      - "5432:5432"
    depends_on:
      - registrator
    volumes:
      - /config/postgres/docker-entrypoint.sh:/docker-entrypoint.sh:ro
#      - postgres-data:/var/lib/postgresql/data
    environment:
      - SERVICE_NAME=postgres
    command: -c max_connections=4000

  test-dbmigrate:
    image: registry.xxx.com/test-db:master
    container_name: test-dbmigrate
    depends_on:
      - postgres
    environment:
      - DEV_LOGGING=1
      - DB_INIT=1
      - DB_HOST=postgres
      - DB_PORT=5432
      - DB_USER=test
      - DB_PASSWORD=xxx
      - PGPASSWORD=xxx

#volumes:
#  postgres-data:

I am getting this error { "timestamp": "2019-06-11T21:08:32.320Z", "level": "ERROR", "thread": "Test worker", "logger": "

1条回答
手持菜刀,她持情操
2楼-- · 2019-08-20 04:14

It worked when I gave a relative path:

volumes:
  - ./docker-entrypoint.sh:/docker-entrypoint.sh
查看更多
登录 后发表回答