Skip to content

Latest commit

 

History

History
49 lines (36 loc) · 1.53 KB

README.md

File metadata and controls

49 lines (36 loc) · 1.53 KB

Example 3

< Go Back

Build somebody else's code

There is a program in the src/ directory, but it doesn't seem to be a well-known language.

Let's solve this problem by making a containerised build environment for it.

Command Arguments Description
FROM <image name> Base image for this image
RUN <shell-command> Run this command when building the image
WORKDIR <directory> Set the current working directory

The GNU D Compiler (gdc) and Make (make) packages should come in handy here.

We use this gadget to install packages from the repositories because:

  • the repository cache should not be shipped with the container;
  • build caching would optimise away the update step if the commands were split into separate RUN invocations.
RUN apt-get update && apt-get install -y \
	<package> \
	<package> && \
	rm -rf /var/lib/apt/lists

Set the current working directory to a sensible location for your source files (i.e. /tmp/src)

Building the image

$ docker build --rm -t workshop-docker/example3 .

Running the image

Mount the source directory into the container and invoke make all && ./example3

$ docker run \
	-it \
	--rm \
	--volume <host directory>:<container directory> \
	workshop-docker/example3 \
	bash -c "<command>"

< Go Back | Solution