asur
asur

Reputation: 1879

Error response from daemon: Container f88566c370dd is not running

I am observing the below error while I execute the below command.

cmd used- docker exec -it f88566c370dd /bin/bash error observed- Error response from daemon: Container f88566c370dd is not running

I am trying to execute a Chef recipe from a VM to pull an image and run three CentOS containers.

Chef recipe

#
# Cookbook Name:: chef-docker
# Recipe:: default    #
# Copyright 2016, SONATA_SOFTWARE    #
# All rights reserved - Do Not Redistribute
#
docker_service 'default' do
  action [:create, :start]
end

# Pull latest image
docker_image 'centos' do
  tag 'latest'
  action :pull
end

# Run container
docker_container 'first' do
  repo 'centos'
  command 'ls -la /'
  end

  docker_container 'second' do
  repo 'centos'
  command 'ls -la /'
  end

  docker_container 'third' do
  repo 'centos'
  command 'ls -la /'
  end

Command used in VM to execute chef recipe

chef-client -r recipe[chef-docker::Default]

Expected Result: Installation of software such as Java, Python, or tools such as Jenkins and Tomcat in containers.

[root@sonatadocker ~]# docker images
REPOSITORY          TAG                 IMAGE ID            CREATED                                                 VIRTUAL SIZE
centos              latest              97cad5e16cb6        3 weeks ago                                             196.5 MB

[root@sonatadocker ~]# docker ps -a
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS                    PORTS               NAMES
f88566c370dd        centos:latest       "ls -la /"          18 hours ago        Exited (0) 17 hours ago                       third
fdc12e9f65a9        centos:latest       "ls -la /"          18 hours ago        Exited (0) 17 hours ago                       second
604f0eba7010        centos:latest       "ls -la /"          18 hours ago        Exited (0) 17 hours ago                       first

Upvotes: 1

Views: 16161

Answers (3)

asur
asur

Reputation: 1879

By changing the command to "/bin/bash" I could see containers in in the up state.

docker_service 'default' do
  action [:create, :start]
end
# Pull latest image
docker_image 'centos' do
  tag 'latest'
  action :pull
end
# Run container
docker_container 'first' do
  repo 'centos'
  command '/bin/bash'
  tty true
  action :run
  end
  docker_container 'second' do
  repo 'centos'
  command '/bin/bash'
  tty true
  action :run
  end

Upvotes: 0

user2599522
user2599522

Reputation: 3225

Your containers run only one command and then exit.

docker_container 'first' do
  repo 'centos'
  command 'ls -la /'
  end

Think of this as spawning a subshell, performing ls -al /, and then exiting.

A hack to keep them up and running will be to change the command to:

ls -la /; sleep 10m

To verify your containers have run the command, you can check the logs of the container with:

docker logs third

Upvotes: 1

YYY
YYY

Reputation: 6341

To keep the container up, Docker needs a command to keep running in the foreground.

In your case, the command "ls -la /" lists the directory contents and exits, which results in exiting the container. Try starting containers with commands which continue to run in the foreground.

Upvotes: 3

Related Questions