0

I have a amazon web server that runs on ubuntu 16.04. This server is dedicated to running a simulation that consists of multiple processes. I have been given the task to create docker containers so that multiple instances of the simulation can be run on the server simultaneously. I understand that running multiple containers will require changing some port id’s for each container so my first task it to just run one instance of the simulation in a container. It seems that I could pull in all of the necessary software images in the dockerFile to create my image file. But I was wondering if there is an easier way to create an image file that is basically a clone of all the software currently on my server?

Thank you

Chase
  • 87
  • 1
  • 6

2 Answers2

0

first get a list of installed packages from your server (source)

dpkg --get-selections > list.txt

then use that list in your dockerfile:

from ubuntu:16.04
add list.txt

RUN dpkg --clear-selections &&\
  dpkg --set-selections < list &&\
  apt-get autoremove &&\
  apt-get dselect-upgrade 

You might also want to copy some folders from your server (etc, var, log, etc). (source)

scp -r user@your.server.example.com:/var /home/user/Desktop/var

and add it to your dockerfile:

ADD /home/user/Desktop/var /var

(repeat for other folders you might need)

and then just build and troubleshoot:

docker build -t my_tag . && docker run -it --rm my_tag bash

Note: This process will get you started, but it will be very very error-prone. Also it will be far from perfect. I recommend, after doing this, to improve your images iteratively by removing unneeded packages and folders. And for a production-docker image, you want to rewrite it to use alpine

Note 2: you can not end up with a docker image, that is identical to your server. Your server has different hardware, a different kernel, a different network, different storage, etc.

wotanii
  • 2,470
  • 20
  • 38
  • Your solution doesn't include packages installed with `tar zxvf package.tar.gz; ./configure; make; make install`. So, is better do a `docker commit` and after that `docker save` of that image. Then is generated a newimage.tar.gz file and you can create the image in other host doing `docker load < newimage.tar.gz` and `docker run`. – Alejandro Galera Jul 17 '18 at 07:21
0

Note: This will probably not work, but if you want an exact copy, this is something you could try

you could just take the entire filesystem and turn it into a docker container (this is how base-images are build, example)

first download entire file-system (source)

ssh user@server "tar czpf - /" > file.gz

and then create a docker-image from it:

FROM scratch
ADD file.gz /

Note: for this to work, you probably have to exclude some directories, like /dev or /tmp

wotanii
  • 2,470
  • 20
  • 38