Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

345
Visualizações
docker python: committed changes in a container but new image does not run

i have a python image called python-example with container_id = c08e4ee85879

Inside exist a python script that prints hello world

file.py

print "HELLO WORLD"

if i run my image: docker run python-example the output HELLO WORLD will be printed on my terminal and then the container will exit.

When i try to enter the container to make a change to the script through vim, exit the container and commit the change to a new image and then try to run the new image, nothing get printed. See steps below

docker run -it python-example bash
vim file.py
#make some changes by adding a new print statement "HELLO WORLD 2"
exit
docker commit c08e4ee85879 python-example2

docker run python-example2 #now nothing gets printed to terminal screen

When i enter the new image then run python file.py, the output gets printed.

docker run -it python-example2 bash
python file.py
"HELLO WORLD"
"HELLO WORLD 2"

Why is this so? Is it not possible for an image to run when changes are commited in bash?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Solution

Change your commit to:

docker commit --change='CMD ["python", "file.py"]' c08e4ee85879 python-example2

Explanation

When you run:

docker run -it python-example bash

you are changing your default command (which is python file.py to bash).

You can check with docker ps.

CONTAINER ID        IMAGE                 COMMAND                  CREATED             STATUS              PORTS               NAMES
c08e4ee85879        python-example        "bash"                   32 seconds ago      Up 30 seconds                           thirsty_hugle

Check dockerfile reference - CMD for more information

With --change='CMD ["python", "file.py"]' you get the desired command back.

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda