简体   繁体   中英

convert Dockerfile to Bash script

Is there any easy way to convert a Dockerfile to a Bash script in order to install all the software on a real OS? The reason is that docker container I can not change and I would like afterwards change few things if they did not work out.

In short - no.

By parsing the Dockerfile with a tool such as dockerfile-parse you could run the individual RUN commands, but this would not replicate the Dockerfile's output.

You would have to be running the same version of the same OS.

The ADD and COPY commands affect the filesystem, which is in its own namespace. Running these outside of the container could potentially break your host system. Your host will also have files in places that the container image would not.

VOLUME mounts will also affect the filesytem.

The FROM image (which may in turn be descended from other images) may have other applications installed.

Writing Dockerfiles can be a slow process if there is a large installation or download step. To mitigate that, try adding new packages as a new RUN command (to take advantage of the cache) and add features incrementally, only optimising/compressing the layers when the functionality is complete.

You may also want to use something like ServerSpec to get a TDD approach to your container images and prevent regressions during development.

Best practice docs here , gotchas and the original article .

Basically you can make a copy of a Docker container's file system using “docker export”, which you can then write to a loop device:

docker build -t <YOUR-IMAGE> ...
docker create --name=<YOUR-CONTAINER> <YOUR-IMAGE>
dd if=/dev/zero of=disk.img bs=1 count=0 seek=1G
mkfs.ext2 -F disk.img
sudo mount -o loop disk.img /mnt
docker export <YOUR-CONTAINER> | sudo tar x -C /mnt
sudo umount /mnt

Convert a Docker container to a raw file system image.

More info here: http://mr.gy/blog/build-vm-image-with-docker.html

You can of course convert a Dockerfile to bash script commands. Its just a matter of determining what the translation means. All docker installs, apply changes to a "file system layer" and that means all changes can be implemented in a real OS.

An example of this process is here: https://github.com/thatkevin/dockerfile-to-shell-script It is an example of how you would do the translation.

you can install application inside dockerfile like this

FROM <base>

RUN apt-get update -y
RUN apt-get install <some application> -y

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM