Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stopping and removing a container doesn't work in docker 1.1.1 #194

Closed
austenito opened this issue Jul 15, 2014 · 4 comments
Closed

Stopping and removing a container doesn't work in docker 1.1.1 #194

austenito opened this issue Jul 15, 2014 · 4 comments

Comments

@austenito
Copy link

When I run the following code, my docker containers aren't removed:

docker_container('foo') do
  action :stop
end

docker_container('foo') do
  action :remove
end

However, when I execute the following command manually, everything works as intended:

execute('stop container') { command "docker stop -t 60 foo" }
execute('remove container') { command "docker rm -f foo" }

Are the stop and remove actions not working how I think they should be?

@bflad
Copy link
Contributor

bflad commented Jul 15, 2014

What happens if you set both actions at same time?

docker_container 'foo' do
  action [:stop, :remove]
end

What's the debug output? Does kill instead of stop help better? Sorry I'm
up in the mountains so my responses will be slow.
On Jul 15, 2014 8:29 AM, "Austen Ito" [email protected] wrote:

When I run the following code, my docker containers aren't removed:

docker_container('foo') do
action :stop
end

docker_container('foo') do
action :remove
end

However, when I execute the following command manually, everything works
as intended:

execute('stop container') { command "docker stop -t 60 foo" }
execute('remove container') { command "docker rm -f foo" }

Are the stop and remove actions not working how I think they should be?


Reply to this email directly or view it on GitHub
#194.

@austenito
Copy link
Author

I tried both stop and remove and got the same error. The container is still running after I run this and the failure happens when I try to run the container again. Here's the debug output:

==> default: ================================================================================
==> default: Error executing action `run` on resource 'docker_container[foo]'
==> default: ================================================================================
==> default:
==> default:
==> default: Mixlib::ShellOut::ShellCommandFailed
==> default: ------------------------------------
==> default: Expected process to exit with [0], but received '1'
==> default: ---- Begin output of docker run  --detach=true --link="postgres-production:db" --name="foo" --publish="3000:3000" --volumes-from="foo-data" ubuntu:ruby-2.1.2 /config/foo/run.sh ----
==> default: STDOUT:
==> default: STDERR: 2014/07/16 02:48:47 Error response from daemon: Conflict, The name foo is already assigned to 9bd5d8f6fffb. You have to delete (or rename) that container to be able to assign foo to a container again.
==> default: ---- End output of docker run  --detach=true --link="postgres-production:db" --name="foo" --publish="3000:3000" --volumes-from="foo-data" ubuntu:ruby-2.1.2 /config/foo/run.sh ----
==> default: Ran docker run  --detach=true --link="postgres-production:db" --name="foo" --publish="3000:3000" --volumes-from="foo-data" ubuntu:ruby-2.1.2 /config/foo/run.sh returned 1

@jbianquetti
Copy link

+1

@chuckg
Copy link

chuckg commented Aug 1, 2014

+1, using docker 1.1.2 on Ubuntu 14.04; stop does not appear to wait properly, causing the "remove" to fail. My best guess is that the delegation to stopping through the service (upstart in this case) is not written to properly block. Passing init_type false to the container allows stop to work properly.

With redeploy (#198) notify

template 'registry environment file' do
  source 'registry_env.erb'
  path registry_env_file_path
  notifies :redeploy, 'docker_container[registry]', :immediately
end

docker_container 'registry' do
  detach true
  port '5000:5000'
  env_file registry_env_file_path
  action :run
end

Output

[2014-07-31T23:40:18+00:00] INFO: template[registry environment file] sending redeploy action to docker_container[registry] (immediate)
  * docker_container[registry] action redeploy[2014-07-31T23:40:18+00:00] INFO: Processing docker_container[registry] action redeploy (seatme_docker::registry line 25)

================================================================================
Error executing action `redeploy` on resource 'docker_container[registry]'
================================================================================


Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of docker rm  e61fcb1f9805685093fe5b613c2575f2118f9d69941a0f072e2ce1a7aaf66836 ----
STDOUT:
STDERR: Error response from daemon: Impossible to remove a running container, please stop it first or use -f
2014/07/31 23:40:19 Error: failed to remove one or more containers
---- End output of docker rm  e61fcb1f9805685093fe5b613c2575f2118f9d69941a0f072e2ce1a7aaf66836 ----
Ran docker rm  e61fcb1f9805685093fe5b613c2575f2118f9d69941a0f072e2ce1a7aaf66836 returned 1


Cookbook Trace:
---------------
/tmp/kitchen/cookbooks/docker/libraries/helpers.rb:272:in `execute_cmd!'
/tmp/kitchen/cookbooks/docker/libraries/helpers.rb:265:in `docker_cmd!'
/tmp/kitchen/cookbooks/docker/providers/container.rb:281:in `remove_container'
/tmp/kitchen/cookbooks/docker/providers/container.rb:48:in `block in class_from_file'

With stop, remove, run

template 'registry environment file' do
  source 'registry_env.erb'
  path registry_env_file_path
  notifies :stop, 'docker_container[registry]', :immediately
  notifies :remove, 'docker_container[registry]', :immediately
  notifies :run, 'docker_container[registry]', :immediately
end

docker_container 'registry' do
  detach true
  port '5000:5000'
  env_file registry_env_file_path
  action :run
end

Output

[2014-07-31T23:45:42+00:00] INFO: template[registry environment file] sending stop action to docker_container[registry] (immediate)
  * docker_container[registry] action stop[2014-07-31T23:45:42+00:00] INFO: Processing docker_container[registry] action stop (seatme_docker::registry line 27)


[2014-07-31T23:45:42+00:00] INFO: template[registry environment file] sending remove action to docker_container[registry] (immediate)
  * docker_container[registry] action remove[2014-07-31T23:45:42+00:00] INFO: Processing docker_container[registry] action remove (seatme_docker::registry line 27)
[2014-07-31T23:45:43+00:00] WARN: Cloning resource attributes for service[registry] from prior resource (CHEF-3694)
[2014-07-31T23:45:43+00:00] WARN: Previous service[registry]: /tmp/kitchen/cookbooks/docker/providers/container.rb:370:in `service_action'
[2014-07-31T23:45:43+00:00] WARN: Current  service[registry]: /tmp/kitchen/cookbooks/docker/providers/container.rb:370:in `service_action'

================================================================================
Error executing action `remove` on resource 'docker_container[registry]'
================================================================================


Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received '1'
---- Begin output of docker rm  e61fcb1f9805685093fe5b613c2575f2118f9d69941a0f072e2ce1a7aaf66836 ----
STDOUT:
STDERR: Error response from daemon: Impossible to remove a running container, please stop it first or use -f
2014/07/31 23:45:43 Error: failed to remove one or more containers
---- End output of docker rm  e61fcb1f9805685093fe5b613c2575f2118f9d69941a0f072e2ce1a7aaf66836 ----
Ran docker rm  e61fcb1f9805685093fe5b613c2575f2118f9d69941a0f072e2ce1a7aaf66836 returned 1


Cookbook Trace:
---------------
/tmp/kitchen/cookbooks/docker/libraries/helpers.rb:272:in `execute_cmd!'
/tmp/kitchen/cookbooks/docker/libraries/helpers.rb:265:in `docker_cmd!'
/tmp/kitchen/cookbooks/docker/providers/container.rb:281:in `remove_container'
/tmp/kitchen/cookbooks/docker/providers/container.rb:273:in `remove'
/tmp/kitchen/cookbooks/docker/providers/container.rb:59:in `block in class_from_file'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants