How can I change the port dynamodb starts on through the Amazon Docker image?
According to this answer, the -port option can be used when executing the dynamodb java file.
However, when running the docker image with this command: docker run -p 8000:8000 amazon/dynamodb-local I do not have the option of specifying the port dynamodb listens to, just the port connected between my host and the container.
Would I have to make my own Dockerfile, specifying the OS and installing dynamodb and whatnot, so I can run the java command and specify my port?
You don't need to rebuild the image. Doing
docker inspect amazon/dynamodb-local
shows that the Entrypoint is set as
"Entrypoint": [
"java"
],
So running the below command gives an error:
$ docker run -p 8001:8001 amazon/dynamodb-local -port 8001
Unrecognized option: -port
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
because we are trying to pass -port argument to java but we need to pass it to DynamoDBLocal.jar.
Once we know that, we can add the jar to the docker run and the following works:
$ docker run -p 8001:8001 amazon/dynamodb-local -jar DynamoDBLocal.jar -port 8001
Initializing DynamoDB Local with the following configuration:
Port: 8001
InMemory: false
DbPath: null
SharedDb: false
shouldDelayTransientStatuses: false
CorsParams: *
I would raise it as a bug but https://hub.docker.com/r/amazon/dynamodb-local/ doesn't mention a public github repo to raise the issue.
I tried the official image to override entry point but there was some unknown error, But you can good to go with this approach.
Just create a New Docker image from amazon/dynamodb-local as a base image.
Build.
docker build -t mydb .
and run it
docker run -it --rm -p 8001:8001 mydb
Below is the Dockerfile
FROM amazon/dynamodb-local
WORKDIR /home/dynamodblocal
ENTRYPOINT ["java", "-jar", "DynamoDBLocal.jar", "-port", "8003"]
As you will see the port.
For some reason docker-compose does not map ports to the host for dynamodb. The next configuration will not work for the dynamodb-local image:
ports:
- "9000:8000"
The workaround is to put the port directly to the command,
-port 9000 is the same as ports: - "9000:9000" in docker-compose.
version: "3.8"
services:
service-dynamodb:
image: amazon/dynamodb-local
image: "amazon/dynamodb-local:latest"
working_dir: /home/dynamodblocal
# -port {number} is the same as
# ports: - {number}:{number} in Docker
command: "-jar DynamoDBLocal.jar -port 9000 -sharedDb -optimizeDbBeforeStartup -dbPath ./data"
volumes:
- ./data:/home/dynamodblocal/data