Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to use a "blank" docker container without any install on it?

Tags:

docker

I'm new to Docker and I think having understood that Docker is a Software virtualization tool (by opposition to OS virtualization). I understand, by this image, that Docker provides a very blank environment with a given file structure and is executing on the kernel Host. What we need to do is to put our application and its dependencies (with no OS) to have a very light portable container of our app.

But it seems there is a dark side of Docker : each Dockerfile begins with a "FROM ".

I saw this and this but I'm not sure to understand. It sounds that Docker is near an kind of simplified OS virtualizer.

I was interesting in the advantage of images size. But if we have to install an OS on each image my "portable" application will be quite heavy quickly.

Is there really no way to use a "blank image" ?

like image 817
Richard Avatar asked Jul 21 '14 13:07

Richard


People also ask

Can we run container without installing Docker?

If you don't need all the GUI and plumbing stuff like me and doing everything via docker run and docker compose anyway, you may don't even need Docker Desktop but can directly run the Docker Daemon and use the CLIs. It's surprisingly easy!

Can we create empty Docker container?

You can start with FROM scratch which is an empty filesystem. Please see the section on Creating a Base Image if you'd like to spin up your own minimal root file system.

Can you build a Docker image without Docker?

Google solves this problem by providing a tool called Kaniko. Kaniko helps you build container images within a container without any access to the Docker daemon. That way, you can execute your build jobs within containers without granting any access to the host filesystem.

Can Docker container exist without image?

Before the docker container can even exist docker templates/images are built using $ docker build CLI. Docker image templates can exist in isolation but containers can't exist without images.


2 Answers

This may be a bit too late. But I just had a use case where I needed to create a bare bone container that I could launch as part of multi-container docker-compose and get into it afterwards via /bin/bash. Keep in mind, a docker container must run a service and the container will be in existence only for as long as the service is running. So, I created this container with just python in it. I copied a 2 line python script that just makes it sleep. Here's what I did. 1. Create the python script wait_service.py with the following code:

    import time
    time.sleep(1000)

2. Create the Dockerfile with just the following lines:

    FROM python:2.7
    RUN mkdir -p /test
    WORKDIR /test
    COPY wait_service.py /test/
    CMD python wait_service.py

3. Build and run the container. Using the container id, I could then get inside it. Please adjust the sleep time based on how long you want to keep this container.

like image 156
Dean Sha Avatar answered Oct 19 '22 01:10

Dean Sha


You can start with FROM scratch which is an empty filesystem.

Please see the section on Creating a Base Image if you'd like to spin up your own minimal root file system.

You might be surprised how many dependencies your application actually has on the root file system, and in the end, it is usually more efficient to use one of the standard root file systems in your FROM statement, as Charles Duffy commented above.

like image 34
Andy Avatar answered Oct 19 '22 00:10

Andy