133
CHAPTER 5 | Designing and Developing Multi-Container and Microservice-Based .NET Applications
You can directly run a Docker Redis container by executing the following Docker CLI command in your
command prompt:
docker run --name some-redis -d redis
The Redis image includes expose:6379 (the port used by Redis), so standard container linking will
make it automatically available to the linked containers.
In eShopOnContainers, the
basket-api
microservice uses a Redis cache running as a container. That
basketdata
container is defined as part of the multi-container
docker-compose.yml
file, as shown in
the following example:
#docker-compose.yml file
#...
basketdata:
image:
redis
expose:
-
"6379"
This code in the docker-compose.yml defines a container named
basketdata
based on the redis
image and publishing the port 6379 internally. This configuration means that it will only be accessible
from other containers running within the Docker host.
Finally, in the
docker-compose.override.yml
file, the
basket-api
microservice for the
eShopOnContainers sample defines the connection string to use for that Redis container:
basket-api:
environment:
# Other data ...
Dostları ilə paylaş: