Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

343
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!