Download and install .sh from Dockerfile - docker

I have a docker image that i have created from a custom dockerfile.
Now i want to install another program on it, that is installed through downloading and then running a .sh file.
I have already curl on the dockerfile and while i know how to download a file with curl in my system, i am not sure if the downloading and installation is the same inside docker - from a dockerfile.
Do i need to download it to a specific directory and do i have to delete it afterwards?

Looking similar to this Run a script in Dockerfile .You can install package using bootstrap scripts and include clean up process if any.

Inside the Docker container mostly same as your operating system, but some of the Docker images doesn't include all the abilities that you can use in your operating system. For example; nano, curl etc. might not work at the beginning, depending on the image. If thats not the case, you can use your container like your operating system. There is no difference.
However, if you want to control the flow, downloaded files etc. you can link a volume between a directory in your operating system and a directory inside the Docker container. After that when you change, add, remove a file in that directory, it will change in your container aswell.

Related

Where do I place a Docker file?

Just got started with Docker and installed Docker Desktop for Mac. It's all a bit confusing what this does, but it seems the GUI does not support creating/viewing images/containers?
So I started creating a docker file manually, but where do I place it? var/lib/docker/ is what people say, but that folder does not exist, although CLI says I already have to containers (created as a test after installation of the Desktop app).
Update: Installed Kitematic alongside the Desktop app through which I can view/create containers.
I like to put it in the root of the project, but you can put it anywhere and use the -f/--file argument for docker build to specify where it's located.
You place to Dockefile in the root of project. Dockerfile has context it means it can copy/add files/directories which are sibling/children of its Directory.

Override a volume when Building docker image from another docker image

sorry if the question is basic but would it be possible to build a docker image from another one with a different volume in the new image? My use case is the following:
Start From image library/odoo (cfr. https://hub.docker.com/_/odoo/)
upload folders into the volume "/mnt/extra-addons"
build a new image, tag it then put it in our internal image repo
how can we achieve that? I would like to avoid putting extra folders into the host filesystem
thanks a lot
This approach seems to work best until the Docker development team adds the capability you are looking for.
Dockerfile
FROM percona:5.7.24 as dbdata
MAINTAINER monkey#blackmirror.org
FROM centos:7
USER root
COPY --from=dbdata / /
Do whatever you want . This eliminates the VOLUME issue. Heck maybe I'll write tool to automatically do this :)
You have a few options, without involving the host OS that runs the container.
Make your own Dockerfile, inherit from the library/odoo Docker image using a FROM instruction, and COPY files into the /mnt/extra-addons directory. This still involves your host OS somewhat, but may be acceptable since you wouldn't necessarily be building the Docker image on the same host you were running it.
Make your own Dockerfile, as in (1), but use an entrypoint script to download the contents of /mnt/extra-addons at runtime. This would increase your container startup time since the download would need to take place before running your service, but no host directories would need be involved.
Personally I would opt for (1) if your build pipeline supports it. That would bake the addons right into the image, so the image itself would be a complete, ready-to-go build artifact.

Is there any way by which we can list out all the dependencies or libraries installed in running docker container?

Is there any way by which we can list out all the dependencies or libraries installed in running docker container?
Not exactly.
You can inspect the history of the image of a container: that will give you an idea of the various operations (RUN, COPY, ADD) done from a base image in order to build said image.
But don't forget a container can be run from an image a simple as SCRATCH (no files) + 1 executable (making only system call). No OS, no bash, no nothing except that one executable.
In that case, there is no dependencies or libraries to list.

Docker Merge Volumes between host and image

I have an application, in which I want to install into a docker image. This particular application has a folder for custom user's plugins. A user can put their plugins for our application there and we will load and execute them. We also ship our application with some plugins already. What I wanted is when I run docker mounting a volume with the -v options it still keeps the contents already in the image in a way like the contents from the image is merged with the ones in the host folder. Is that possible? Is there another solution that not involves a refactor in the app to support loading from multiple folders to achieve that?
You can mount them into your /plugins/customplugin1. In that case ls plugins should show
customplugin1
standardplugin
standardplugin2

How to place files on shared volume from within Dockerfile?

I have a Dockerfile which builds an image that provides for me a complicated tool-chain environment to compile a project on a mounted volume from the host machines file system. Another reason is that I don't have a lot of space on the image.
The Dockerfile builds my tool-chain in the OS image, and then prepares the source by downloading packages to be placed on the hosts shared volume. And normally from there I'd then log into the image and execute commands to build. And this is the problem. I can download the source in the Dockerfile, but how then would I get it to the shared volume.
Basically I have ...
ADD http://.../file mydir
VOLUME /home/me/mydir
But then of course, I get the error 'cannot mount volume over existing file ..."
Am I going about this wrong?
You're going about it wrong, but you already suspected that.
If you want the source files to reside on the host filesystem, get rid of the VOLUME directive in your Dockerfile, and don't try to download the source files at build time. This is something you want to do at run time. You probably want to provision your image with a pair of scripts:
One that downloads the files to a specific location, say /build.
Another that actually runs the build process.
With these in place, you could first download the source files to a location on the host filesystem, as in:
docker run -v /path/on/my/host:/build myimage fetch-sources
And then you can build them by running:
docker run -v /path/on/my/host:/build myimage build-sources
With this model:
You're trying to muck about with volumes during the image build process. This is almost never what you want, since data stored in a volume is explicitly excluded from the image, and the build process doesn't permit you to conveniently mount host directories inside the container.
You are able to download the files into a persistent location on the host, where they will be available to you for editing, or re-building, or whatever.
You can run the build process multiple times without needing to re-download the source files every time.
I think this will do pretty much what you want, but if it doesn't meet your needs, or if something is unclear, let me know.

Resources