https://docs.docker.com/compose/gettingstarted/#step-3-define-services-in-a-compose-file
- go through the tutorial on the above link
- run
docker-compose up
That's it.
NOTE:
docker-compose
automatically links the redis with the app services accessing port '6379', which is the default exposed port of redis.- the redis container created through this process can NOT be accessed by other containers outside of services defined in
docker-compose
. (docker: Error response from daemon: Cannot link to /playarounddocker_redis_1, as it does not belong to the default network)
https://docs.docker.com/get-started/part2/#build-the-app
(start point is app.py
)
cd app
- run
docker build -t docker-init .
, which build an image based onDockerfile
, andDockerfile
usesapp.py
as an entry point - run
docker pull redis
to get redis image - run
docker run --name redis -p 6379:6379 redis
to create a container of reids. DO NOT forget to config the port!!! - run
docker run --name hello-redis-3 --link redis -p 4040:80 docker-init
, create a container of our app and link it to redis (NOTE: you have to link the redis container here. Different containers may expose same port number, so define the redis port in app.py isn't sufficient) - open link
http://localhost:4040/
in browser
docker rm $(docker ps -a -q)
docker rmi $(docker images -q)