Docker Community Forums

Share and learn in the Docker community.

Need to create a dockerfile template to deploy the contained needed into the VM


(Brickclick) #1


1- I want to create a dockerfile template and let user specific what container they want. We modify the dockerfile to deploy the contained needed into the VM.
2- And can allow user to have multiple containers in single VM.

(Kylesoskin) #2

I’m not sure docker files really have the ability to deploy the images they make to places.

A dockerfile will give you an image. This image can then be put anywhere where a docker daemon can run.

So you could write a script to make your image via the docker file, push the newly created image to docker hub (or your own private registry if you use one). You can then set the DOCKER_HOST=tcp://$vm_where_you_want_this_to_go:2375 and run a docker pull of the new image. This will essentially pull the newly created image down in the vm, via the docker daemon on that host. Now it can be used on that host.


Here is an example

The docker file… named Dockerfile
FROM Ubuntu:latest
RUN echo 'echoing something in docker container’s

In same directory as that file
docker build -t some_tag_name .

That will build you an image named some_tag_name from your dockerfile

Then, you can do
docker push some_tag_name
To push it up to docker hub

Then whatever vm you want to be able to run this on (assuming it has docker daemon running, and listening on the default port of 2375)

You can just run
DOCKER_HOST=tcp://$vm_ip:2375 docker pull your_docker_hub/some_tag_name
And it will pull onto that vm. So now anyone on that vm can use that image.

(Brickclick) #3

down vote

I am looking for an approach for below.

User to have multiple containers in single VM. Issue is how should I bootstrap this from my local machine so that I can see Docker image with three containers running with different applications. Created below Chef recipe for the same.

docker_service ‘default’ do
action [:create, :start]

include_recipe 'docker’
docker_node_data = '/tmp/docker1’
directory docker_node_data do
action :create

cookbook_file “#{docker_node_data}/Dockerfile” do
source 'Dockerfile’

docker_image ‘centos1’ do
tag 'latest’
source docker_node_data
action :build

docker_container ‘sample1’ do
repo 'centos’
command 'top -b -d 5’

docker_container ‘check3’ do
repo 'centos’
command 'top -b -d 5’

docker_container ‘check4’ do
repo 'centos’
command 'top -b -d 5’

DockerFile is

FROM centos
maintainer UTE
RUN yum update && yum install -y openssh-server
RUN mkdir /var/run/sshd
RUN echo ‘root:screencast’ | chpasswd
RUN sed -i ‘s/PermitRootLogin prohibit-password/PermitRootLogin yes/’ /etc/ssh/sshd_config

SSH login fix. Otherwise user is kicked off after login

RUN sed ‘s@session\srequired\ optional’ -i /etc/pam.d/sshd

ENV NOTVISIBLE "in users profile"
RUN echo “export VISIBLE=now” >> /etc/profile

CMD ["/usr/sbin/sshd", “-D”]