I´m trying to create an image in docker for my container. This image must have python 3.10 version, ubuntu last version and git. I´ve created the nex Dockerfile:
FROM ubuntu:22.04
RUN apt-get update &&
apt-get install -y git &&
apt-get install -y python3.10 &&
apt-get clean
EXPOSE 6379
Once created y saved it in a new directory and opend that directory in windows powershel and executed the next command to create the image: docker build -t py3_10 .
It creates the image without problems, then I create the container docker run -d -p 6379:6379 --name pyth py3_10
and it does it without error. But, when i try to execute the container docker exec -it pyth bash
the next error appears: Error response from daemon: Container a5ffdf1112f24c3... is not running
Shoul I change something or add something in the Dockerfile?
2
Answers
You need, to add this line at the end of your Dockerfile
Because your container, starts, installs its dependancies and then… it has nothing to do any more so it ends.
With this line, it will run a bash, and then your
docker exec -it
will be able to "attach" to itHope it helps
Docker containers exist for the lifetime of their entrpoint process. Your dockerfile has no
CMD
orENTRYPOINT
to keep running. You can set one in the Dockerfile.If the CMD / ENTRYPOINT is a shell like bash, you will need to allocate a terminal to keep it running. Otherwise the shell will dutifully close at end of input.
You could try something like this:
When you try to execute additional commands in container context.
run
runs the container, and whenrun
‘s process ends, the container stops.exec
only works in the mean time.I recommend thinking of containers as runtimes, not development environments. Seems like you think of the container as a virtual machine that you would shell into to do python 10 development. Instead think of it as a set of libraries providing python 10 to whatever code you want to run there. Dockerfiles are generally project specific, and would include commands to
ADD
/COPY
the project’s codebase into the container, install dependencies, and then the entrypoint would be the invocation of the project’s main executable.