Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

share images between host and child docker

Tags:

docker

I read this article http://blog.docker.io/2013/09/docker-can-now-run-within-docker/ and I want to share images between my "host" docker and "child" docker. But when I run

sudo docker run -v /var/lib/docker:/var/lib/docker -privileged -t -i jpetazzo/dind

I can't connect to "child" docker from dind container.

     root@5a0cbdc2b7df:/# docker version
     Client version: 0.8.1
     Go version (client): go1.2
     Git commit (client): a1598d1
     2014/03/13 18:37:49 Can't connect to docker daemon. Is 'docker -d' running on this host?

How can I share my local images between host and child docker?

like image 389
user1041996 Avatar asked Mar 13 '14 18:03

user1041996


People also ask

How do I share my Docker images with others?

To share Docker images, you have to use a Docker registry. The default registry is Docker Hub and is where all of the images we've used have come from. A Docker ID allows you to access Docker Hub which is the world's largest library and community for container images. Create a Docker ID for free if you don't have one.

Are Docker images shared between users?

Docker makes it easy to share application images and development environments with your collaborators.

How do I move Docker images from one host to another?

In order to transfer a Docker image from one server to another, what you need to do is first export the image to a file, then copy that file over from your current server to the new one using scp or rsync and finally load the image to your new server.


1 Answers

You shouldn't do that! Docker assumes that it has exclusive access to /var/lib/docker, and if you (or another Docker instance) meddles with this directory, it could have unexpected results.

There are multiple solutions, depending on what you want to achieve.

  • If you want to be able to run Docker commands from within a container, but don't need a separate daemon, then you can share the Docker control socket with this container, e.g.:

    docker run -v /var/run/docker.sock:/var/run/docker.sock \
               -v /usr/bin/docker:/usr/bin/docker \
               -t -i ubuntu bash
    
  • If you really want to run a different Docker daemon (e.g. because you're hacking on Docker and/or want to run a different version), but want to access the same images, maybe you could run a private registry in a container, and use that registry to easily share images between Docker-in-the-Host and Docker-in-the-Container.

Don't hesitate to give more details about your use-case so we can tell you the most appropriate solution!

like image 90
jpetazzo Avatar answered Oct 05 '22 21:10

jpetazzo