Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extend docker container

Tags:

java

docker

I am new to Docker and I have a question regarding possibility to extend docker image after pulling it from docker repository. I need specifically docker image with ubuntu 14.04, java and R. I see there are images separately with the three of them. My question is where is the Dockerfile of newly pulled images so I can extend them?

like image 422
user2266685 Avatar asked Aug 18 '14 13:08

user2266685


People also ask

How do I show containers created by extensions in Docker?

By default, containers created by extensions are hidden from the list of containers in Docker Dashboard and the Docker CLI. To make them visible update your settings: Navigate to Settings, or Preferences if you’re a Mac user. Next to Show Docker Extensions system containers, select or clear the checkbox to set your desired state.

What is the use of extends in Docker?

The extends keyword has been included in docker-compose versions 1.27 and higher. Docker Compose’s extends keyword enables the sharing of common configurations among different files, or even different projects entirely. Extending services is useful if you have several services that reuse a common set of configuration options.

Should You Expand Your Docker containers?

Usually the docker container size expansion is required in scenarios where the disk usage is high and there isn’t enough space for hosting an application or a service in it. But changing the size limits and directory settings of existing containers involves data loss.

How do I install Docker extensions on Ubuntu?

In the bottom-right corner, click Apply & Restart. You can install Docker Extensions through the Marketplace or through the Extensions SDK tools. You can choose to only allow published extensions (that have been published in the Extensions Marketplace). Navigate to Settings, or Preferences if you’re a Mac user.


2 Answers

docker pull command just pull a pre-built image. There isn't Dockerfile on your local machine. But you can find the original Dockerfile from Docker Hub. If you use itzg/ubuntu-openjdk-7 image you can access it's online repository.

https://registry.hub.docker.com/u/itzg/ubuntu-openjdk-7/

Dockerfile is available on Dockerfile tab(Only "Automated Build" repositories have Dockefile tab on Docker Hub).

FROM ubuntu:trusty
MAINTAINER itzg
ENV APT_GET_UPDATE 2014-07-19
RUN apt-get update
RUN apt-get install -y openjdk-7-jre-headless
ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64

Below is another Dockerfile from edwindj/docker-r.

FROM ubuntu:trusty
MAINTAINER Edwin de Jonge
RUN apt-get update
RUN apt-get install -y r-base

There is no method to automatically merge two or more Dockerfiles, but you can combine these two Dockerfile like below.

FROM ubuntu:trusty
RUN apt-get update

# Install java
RUN apt-get install -y openjdk-7-jre-headless
ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64

# Install R
RUN apt-get install -y r-base

And build it with docker build command.

$ docker build nacyot/ubuntu-java-r .

Try to java and R command on the container which based on nacyot/ubuntu-java-r image.

$ docker run -it nacyot/ubuntu-java-r cat /etc/lsb-release 
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=14.04
DISTRIB_CODENAME=trusty
DISTRIB_DESCRIPTION="Ubuntu 14.04.1 LTS"

$ docker run -it nacyot/ubuntu-java-r java -version
java version "1.7.0_55"
OpenJDK Runtime Environment (IcedTea 2.4.7) (7u55-2.4.7-1ubuntu1)
OpenJDK 64-Bit Server VM (build 24.51-b03, mixed mode)

$ docker run -it nacyot/ubuntu-java-r R --version
R version 3.0.2 (2013-09-25) -- "Frisbee Sailing"
Copyright (C) 2013 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under the terms of the
GNU General Public License versions 2 or 3.
For more information about these matters see
http://www.gnu.org/licenses/.

It works fine.

There is no magic, but you can extend and bulid (almost) any images which have packages you need at first hand by referencing Dockerfiles on Docker Hub.

like image 117
nacyot Avatar answered Sep 28 '22 07:09

nacyot


Dockerfiles are made to build image but you the inverse operation isn't possible.

If you want to extend an existing image you have 2 solution.

  • Run your image in a container, do the change and then commit to a new image. https://docs.docker.com/reference/commandline/cli/
  • Write a Dockerfile with the image you want as base. (1st line of Dockerfile should be FROM myimage) https://docs.docker.com/reference/builder/
like image 23
Regan Avatar answered Sep 28 '22 07:09

Regan