How to link binaries between docker containers

Can I use docker to push a binary file from one container to another container?

For example, I have 2 containers:

  • centos6
  • sles11

I need both of these containers to install similar versions of git. Unfortunately, the sles container does not have the git version that I need.

I want to deploy the git container as follows:

$ cat Dockerfile FROM ubuntu:14.04 MAINTAINER spuder RUN apt-get update RUN apt-get install -yq git CMD /usr/bin/git # ENTRYPOINT ['/usr/bin/git'] 

Then bind the centos6 and sles11 containers to the git container so that they both have access to the git binary without experiencing problems installing it.

I am having the following issues:

  • You cannot associate a container with another container not running
  • I'm not sure what docker containers are supposed to be used.

Looking at the docker documentation , it looks like related containers have common environment variables and ports, but not necessarily access to every entry point.

How can I bind the git container so that the cent and sles containers can access this command? Is it possible?

+5
source share
1 answer

You can create a dedicated git container and set the data loaded by it as volume , and then share this volume with the other two containers (centos6 and sles11). Volumes are available even if the container is not working.

If you want two other containers to be able to run git from a dedicated git container, you will need to set (or copy) that git is a binary file on a shared volume.

Please note that volumes are not part of the image, so they are not saved or exported when you docker save or docker export . They must be reserved separately.

Example

Dockerfile:

 FROM ubuntu RUN apt-get update; apt-get install -y git VOLUME /gitdata WORKDIR /gitdata CMD git clone https://github.com/metalivedev/isawesome.git 

Then run:

 $ docker build -t gitimage . # Create the data container, which automatically clones and exits $ docker run -v /gitdata --name gitcontainer gitimage Cloning into 'isawesome'... # This is just a generic container, but what I do in the shell # you could do in your centos6 container, for example $ docker run -it --rm --volumes-from gitcontainer ubuntu /bin/bash root@e01e351e3ba8 :/# cd gitdata/ root@e01e351e3ba8 :/gitdata# ls isawesome root@e01e351e3ba8 :/gitdata# cd isawesome/ root@e01e351e3ba8 :/gitdata/isawesome# ls Dockerfile README.md container.conf dotcloud.yml nginx.conf 
+1
source

Source: https://habr.com/ru/post/1200167/


All Articles