What is happening here is that you are spawning an instance of Python and then not providing the command any arguments. Docker containers are essentially abstractions around filesystems and resources for single processes from the kernel of the Host OS.
So, in this case, the image you are calling just simply gets created and then calls Python. What happens if you call Python in your shell on your computer? It dumps you into an interactive shell that you can then submit commands to.
Well, that doesn't make much sense. Why call a command that just spins up a shell in a namespaced environment that can't communicate with anything else? The real way to use Docker would be to pass arguments to that container image. So that when Docker starts up the Python process, it can pass it an argument to do something. For example, run an application that was volume mounted in or copied in via the Dockerfile.
So how do we do that? Well, we can provide your docker-compose file with some Arguments through the Args field!
But, to me, it looks like you're just playing around here. So you likely don't have a project to pass to Python with the args field. Or to back into a new Docker Image. What you're likely trying to do is to get into the shell of Python.
The reason that this doesn't automatically happen when Docker runs the python
command, is because docker-compose up
or docker run
doesn't drop you into an interactive environment. It just calls the entrypoint command in the container. To do that, you have to call an ADDITIONAL command in the container. In this case, a shell. Most container OS come with something like sh
or bash
installed on them. I DOUBT that python
does. However, you can test it using the exec command like so:
docker-compose up -d
docker exec -it test_c
Let me know if you need any additional info or support for this question. Always happy to help you get started with Docker. It's an awesome technology!