So far in my DevOps class I’ve encountered three separate places where we use parameterized commands to perform some of the Docker setup and runtime execution.
I’ve been having a conceptual crisis of confidence because I don’t definitively understand which kinds of commands go where. So this is my exercise in deciphering the lay of the land.
Dockerfile, docker-compose.yml, docker-compose run
Here’s what I think I have inferred from what we’ve done in class tutorials:
- Dockerfile
- can contain one or more commands prefaced with the RUN directive
- these will run commands outside of the to-be-built Docker container, to setup the appropriate files and environment to make the build successful
- presumably you should do as little as necessary out here
- example command: RUN pip install -r requirements.txt
- docker-compose.yml
- configures the set of containers that will be built and run together (one or more)
- command to be run once the container is up and running
- ?? Only one command can be configured per container ??
- example command: command: gunicorn fooapi.wsgi:application -b :8000
- docker-compose run [container_name]
- commands can be run one time, arbitrarily, outside the build process itself
- example command: docker-compose run web django-admin.py startproject fooapi .
My Confusions
- If my web application needs to have all the python packages installed as dependencies, why isn’t pip install -r requirements.txt being run once the appropriate container is up and running?
- If the use of a RUN command in Dockerfile creates a scratch space outside all containers, why would I need to install python dependencies to be able to create a PostgreSQL container cf. Assignment 3? [Leaving aside the advice I’ve heard that putting databases in containers isn’t generally necessary or advisable]
- What is the net effect of running commands inside the “docker-compose run [container_name]” wrapper? Why couldn’t/shouldn’t I run that command as a RUN command from the Dockerfile, and then copy the resulting files into the /code folder that we’re creating in Assignment 3?
- Does docker-compose run run commands inside an already-built container?
As I learn answers to these questions, with any luck I’ll return here to annotate what I’ve learned.