How can I implement the below docker-compose
code, but using the docker run
command? I am specifically interested in the depends_on
part.
version: '2'
services:
db:
image: postgres
web:
build: .
command: python manage.py runserver 0.0.0.0:8000
volumes:
- .:/code
ports:
- "8000:8000"
depends_on:
- db
CodePudding user response:
depends_on:
doesn't map to a docker run
option. When you have your two docker run
commands you need to make sure you put them in the right order.
docker build -t web_image .
docker network create some_network
docker run --name db --net some_network postgres
# because this depends_on: [db] it must be second
docker run --name web --net some_network ... web_image ...
CodePudding user response:
depends-on mean :
Compose implementations MUST guarantee dependency services have been started before starting a dependent service. Compose implementations MAY wait for dependency services to be “ready” before starting a dependent service.
Hence the depends on is not only an order of running and you can use docker-compose instead of docker run and every option in docker run can be in the docker-compose file