user1079608
user1079608

Reputation: 11

Docker containers exit after start command

I'm trying to create a docker container that adds python image from docker hub using a chef recipe. After chef-client run, I can see the container but it is not getting started even after issuing start command.

Here is my cookbook recipe to pull python image,

docker_service 'default' do
  action [:create, :start]
end

docker_image 'python' do
  tag 'latest'
  action :pull
end

docker_container 'testpy' do
  repo 'python'
  tag 'latest'
  action :run
end

Below is the issue with the container,

root@ubuntunode2-vm:~# docker start 2e512235c0fe
2e512235c0fe

root@ubuntunode2-vm:~# docker exec -it 2e512235c0fe bash

Error response from daemon: Container 2e512235c0fe50b6314648b9d6eae6162790e0793008344d27288d95c69d4923 is not running

Hightlighted container in the screenshot is created through chef recipe

Upvotes: 1

Views: 171

Answers (2)

Dusan Gligoric
Dusan Gligoric

Reputation: 584

Python's interactive shell needs tty in order to run, add tty: true to the docker_container block and you should be good to go.

Upvotes: 0

Mr.
Mr.

Reputation: 10102

since your question does not include full details, the answer will be focused on your recipe.

under the assumption that you are using docker cookbook:

  1. install docker engine. you can do that using docker_installtion resource. i prefer docker_installation_package resource, in order to use the linux repository package of docker and pin the package version
  2. once docker engine is installed, let's make sure that docker engine daemon (service) is running. for that you can use the (native) service resource. note that, there is docker_service resource within the docker cookbook, but i prefer the native service method
  3. pull the docker image using docker_image resource
  4. use docker_container resource to run the pulled docker image

Upvotes: 1

Related Questions