I'm trying to understand how to create a custom image.
I'm working on an application that is in node.js and uses catdoc to extract text from text files.
I did pull the office node.js image through dockerhub :
git pull node
docker run -p 8080:3000 -v $(PWD):/my-app -w "/my-app" node npm start
docker exec <node_container_id> apt-get install catdoc
Reading package lists...
Building dependency tree...
Reading state information...
E: Unable to locate package catdoc
docker exec <ubuntu_container_id> apt-get node
rpc error: code = 2 desc = oci runtime error: exec failed: exec: "apt-get": executable file not found in $PATH
The official Node image on Docker Hub is based on Jessie (Debian) according to the Dockerfile. Docker images are usually as compact as possible, which means that things like
apt caches are flushed before creating the image.
apt-get install catdoc fails because the apt package list is empty. If you run
apt-get update before, it should work:
$ docker run --rm -ti node bash root@5ef87ec1e333:/# apt-get update Get:1 http://security.debian.org jessie/updates InRelease [63.1 kB] Ign http://httpredir.debian.org jessie InRelease Get:2 http://security.debian.org jessie/updates/main amd64 Packages [374 kB] Get:3 http://httpredir.debian.org jessie-updates InRelease [142 kB] Get:4 http://httpredir.debian.org jessie Release.gpg [2373 B] Get:5 http://httpredir.debian.org jessie Release [148 kB] Get:6 http://httpredir.debian.org jessie-updates/main amd64 Packages [17.6 kB] Get:7 http://httpredir.debian.org jessie/main amd64 Packages [9032 kB] Fetched 9780 kB in 5s (1762 kB/s) Reading package lists... Done root@5ef87ec1e333:/# apt-get install catdoc Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: tk wish The following NEW packages will be installed: catdoc 0 upgraded, 1 newly installed, 0 to remove and 4 not upgraded. Need to get 650 kB of archives. After this operation, 2504 kB of additional disk space will be used. Get:1 http://httpredir.debian.org/debian/ jessie/main catdoc amd64 0.94.4-1.1 [650 kB] Fetched 650 kB in 0s (679 kB/s) debconf: delaying package configuration, since apt-utils is not installed Selecting previously unselected package catdoc. (Reading database ... 21090 files and directories currently installed.) Preparing to unpack .../catdoc_0.94.4-1.1_amd64.deb ... Unpacking catdoc (0.94.4-1.1) ... Processing triggers for mime-support (3.58) ... Setting up catdoc (0.94.4-1.1) ... root@5ef87ec1e333:/# catdoc Usage: catdoc [-vu8btawxlV] [-m number] [-s charset] [-d charset] [ -f format] files
You might want to write your own Dockerfile to create an image containing Node,
catdoc and whatever tools you might need, and base your containers on that image instead of the official one. For example, create a Dockerfile containing (see the documentation for more information about the
FROM node RUN apt-get update && \ apt-get install catdoc && \ rm -rf /var/lib/apt/lists/*
Then build your image with
docker build -t="test:test" . and create a container based on it:
$ docker run --rm -ti test:test bash root@eb7f087a2cbd:/# catdoc Usage: catdoc [-vu8btawxlV] [-m number] [-s charset] [-d charset] [ -f format] files