Home > Net >  Starting docker containers
Starting docker containers

Time:11-13


I have a docker-compose.yml file that starts two services: amazon/dynamodb-local on 8000 port and django-service. django-service runs tests that are dependent on dynamodb-local.

Here is working docker-compose.yml:

version: '3.8'
services:
  dynamodb-local:
    image: "amazon/dynamodb-local:latest"
    container_name: dynamodb-local
    ports:
      - "8000:8000"
  django-service:
    depends_on:
      - dynamodb-local
    image: django-service
    build:
      dockerfile: Dockerfile
      context: .
    env_file:
      - envs/tests.env
    volumes:
      - ./:/app
    command: sh -c 'cd /app && pytest tests/integration/ -vv'

Now I need to run this without docker-compose, only using docker itself.
I try to do following:

docker network create -d bridge net // create a network for dynamodb-local and django-service
docker run --network=net --rm -p 8000:8000 -d amazon/dynamodb-local:latest // run cont. att. to network
docker run --network=net --rm --env-file ./envs/tests.env -v `pwd`:/app django-service /bin/sh -c 'env && cd /app && pytest tests/integration -vv'

I can see that both services start, but I can't connect to the dynamo-db.

Where is the problem? Any comment or help is appreciated!

CodePudding user response:

Through the docker-compose.yml, the amazon/dynamodb-local container has a name defined (container_name: dynamodb-local, If we do not set this property, docker-compose will use the service's name as container name). This enables other containers in the same network to address the container through its name.

In the docker-run command, we do not set an explicit container name. We can set an explicit container name by executing docker run ... --name dynamodb-local .... More details can be found in the corresponding docker run documentation.

  • Related